You have requested a non-existent service entity.manager Drupal 9

Created on 11 February 2022, almost 3 years ago
Updated 25 April 2023, over 1 year ago

Problem/Motivation

Following error message appears with Drupal 9 (tested with D9.3.3 and 3.3.5)

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "entity.manager". in Drupal\Component\DependencyInjection\Container->get() (line 156 of core/lib/Drupal/Component/DependencyInjection/Container.php).

Drupal\external_data_source\Plugin\Field\FieldFormatter\ExternalDataSourceFormatter::create(Object, Array, 'external_data_source_formatter', Array) (Line: 64)
Drupal\Core\Field\FormatterPluginManager->createInstance('external_data_source_formatter', Array) (Line: 126)

Steps to reproduce

Proposed resolution

In web/modules/contrib/external_data_source/src/Plugin/Field/FieldFormatter/ExternalDataSourceFormatter.php do the following change fix the issue for me.

diff --git a/src/Plugin/Field/FieldFormatter/ExternalDataSourceFormatter.php b/src/Plugin/Field/FieldFormatter/ExternalDataSourceFormatter.php
index 091a52d..11e208e 100755
--- a/src/Plugin/Field/FieldFormatter/ExternalDataSourceFormatter.php
+++ b/src/Plugin/Field/FieldFormatter/ExternalDataSourceFormatter.php
@@ -3,7 +3,7 @@
 namespace Drupal\external_data_source\Plugin\Field\FieldFormatter;
 
 use Drupal\Component\Utility\Html;
-use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Field\FieldDefinitionInterface;
 use Drupal\Core\Field\FieldItemInterface;
 use Drupal\Core\Field\FieldItemListInterface;
@@ -48,7 +48,7 @@ class ExternalDataSourceFormatter extends FormatterBase implements ContainerFact
    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
    *   The entity manager.
    */
-  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityManagerInterface $entity_manager) {
+  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, EntityTypeManagerInterface $entity_manager) {
     parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
 
     $this->entityManager = $entity_manager;
@@ -59,7 +59,7 @@ class ExternalDataSourceFormatter extends FormatterBase implements ContainerFact
    */
   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
     return new static(
-      $plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], $container->get('entity.manager')
+      $plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], $container->get('entity_type.manager')
     );
   }
 

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: duplicate

Version

3.0

Component

Code

Created by

🇫🇷France ErwanMaire

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024