Commit eb4ef5ed authored by marcvangend's avatar marcvangend

finish implementing the DIC in the FieldBlock deriver class

parent d237c6de
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
namespace Drupal\fieldblock\Plugin\Derivative; namespace Drupal\fieldblock\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase; 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\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
...@@ -22,13 +23,34 @@ class FieldBlock extends DeriverBase implements ContainerDeriverInterface { ...@@ -22,13 +23,34 @@ class FieldBlock extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait; 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} * {@inheritdoc}
*/ */
public static function create(ContainerInterface $container, $base_plugin_id) { public static function create(ContainerInterface $container, $base_plugin_id) {
$foo = 'bar'; /** @var EntityManagerInterface $entity_manager */
$entity_manager = $container->get('entity.manager');
return new static( return new static(
$base_plugin_id, $entity_manager->getStorage('entity_view_display'),
$container->get('string_translation') $container->get('string_translation')
); );
} }
...@@ -57,7 +79,7 @@ class FieldBlock extends DeriverBase implements ContainerDeriverInterface { ...@@ -57,7 +79,7 @@ class FieldBlock extends DeriverBase implements ContainerDeriverInterface {
$fieldblocks = array(); $fieldblocks = array();
// Get all EntityViewDisplay config entities and iterate over them. // 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 */ /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $entity_view_display */
foreach ($entity_view_displays as $display_id => $entity_view_display) { foreach ($entity_view_displays as $display_id => $entity_view_display) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment