diff --git a/src/Plugin/Field/FieldFormatter/EntityReferenceDisplayFormatterTrait.php b/src/Plugin/Field/FieldFormatter/EntityReferenceDisplayFormatterTrait.php index 8b15c088fd4109c42d9c6f906922b4c3c3979335..a504e071897cb0c574b6e56c051a8a17e71cba85 100644 --- a/src/Plugin/Field/FieldFormatter/EntityReferenceDisplayFormatterTrait.php +++ b/src/Plugin/Field/FieldFormatter/EntityReferenceDisplayFormatterTrait.php @@ -2,8 +2,6 @@ namespace Drupal\entity_reference_display\Plugin\Field\FieldFormatter; -use Drupal\Core\Entity\EntityFieldManagerInterface; -use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; @@ -15,23 +13,27 @@ use Symfony\Component\DependencyInjection\ContainerInterface; trait EntityReferenceDisplayFormatterTrait { /** - * Constructs a new MyEntityReferenceDisplayFormatter. + * The entity repository service. * - * @param \Drupal\Core\Entity\EntityRepositoryInterface $entityRepository - * The entity repository service. - * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager - * The entity field manager service. + * @var \Drupal\Core\Entity\EntityRepositoryInterface */ - public function __construct(protected EntityRepositoryInterface $entityRepository, protected EntityFieldManagerInterface $entityFieldManager) {} + protected $entityRepository; + + /** + * The entity field manager service. + * + * @var \Drupal\Core\Entity\EntityFieldManagerInterface + */ + protected $entityFieldManager; /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $container->get('entity.repository'), - $container->get('entity_field.manager') - ); + $instance = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $instance->entityRepository = $container->get('entity.repository'); + $instance->entityFieldManager = $container->get('entity_field.manager'); + return $instance; } /** @@ -115,7 +117,7 @@ trait EntityReferenceDisplayFormatterTrait { $entity_bundle = $field_definition->getTargetBundle(); if (!empty($entity_bundle)) { $entity_fields = \Drupal::service('entity_field.manager') - ->getFieldDefinitions($entity_type, $entity_bundle); + ->getFieldDefinitions($entity_type, $entity_bundle); /** @var \Drupal\Core\Field\FieldDefinitionInterface $field */ foreach ($entity_fields as $field) { // Formatter is only available for entity types with display mode field.