From eb4ef5ed54ba22e51521dfaf17834e4fa98c64ff Mon Sep 17 00:00:00 2001 From: Marc van Gend <marc@triquanta.nl> Date: Thu, 9 Oct 2014 16:17:30 +0200 Subject: [PATCH] finish implementing the DIC in the FieldBlock deriver class --- src/Plugin/Derivative/FieldBlock.php | 30 ++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Plugin/Derivative/FieldBlock.php b/src/Plugin/Derivative/FieldBlock.php index 1fe32bd..0d5a670 100644 --- a/src/Plugin/Derivative/FieldBlock.php +++ b/src/Plugin/Derivative/FieldBlock.php @@ -8,9 +8,10 @@ namespace Drupal\fieldblock\Plugin\Derivative; use Drupal\Component\Plugin\Derivative\DeriverBase; -use Drupal\Core\Entity\Entity\EntityViewDisplay; +use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -22,13 +23,34 @@ class FieldBlock extends DeriverBase implements ContainerDeriverInterface { use StringTranslationTrait; + /** + * The entity view display storage. + * + * @var \Drupal\Core\Entity\EntityStorageInterface + */ + protected $entityViewDisplayStorage; + + /** + * Constructs a FieldBlock deriver object. + * + * @param \Drupal\Core\Entity\Entity\EntityViewDisplay $entity_view_display + * The entity view display storage. + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation + * The string translation. + */ + public function __construct($entity_view_display, TranslationInterface $string_translation) { + $this->entityViewDisplayStorage = $entity_view_display; + $this->stringTranslation = $string_translation; + } + /** * {@inheritdoc} */ public static function create(ContainerInterface $container, $base_plugin_id) { - $foo = 'bar'; + /** @var EntityManagerInterface $entity_manager */ + $entity_manager = $container->get('entity.manager'); return new static( - $base_plugin_id, + $entity_manager->getStorage('entity_view_display'), $container->get('string_translation') ); } @@ -57,7 +79,7 @@ class FieldBlock extends DeriverBase implements ContainerDeriverInterface { $fieldblocks = array(); // Get all EntityViewDisplay config entities and iterate over them. - $entity_view_displays = EntityViewDisplay::loadMultiple(); + $entity_view_displays = $this->entityViewDisplayStorage->loadMultiple(); /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $entity_view_display */ foreach ($entity_view_displays as $display_id => $entity_view_display) { -- GitLab