From d237c6de5c68cf6624cc8a4c4f88970f5d8e9cf9 Mon Sep 17 00:00:00 2001 From: marcvangend <info@marcvangend.nl> Date: Thu, 9 Oct 2014 08:19:48 +0200 Subject: [PATCH] wip - try to inject string translation into deriver class --- src/Plugin/Derivative/FieldBlock.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Plugin/Derivative/FieldBlock.php b/src/Plugin/Derivative/FieldBlock.php index a2e52d2..1fe32bd 100644 --- a/src/Plugin/Derivative/FieldBlock.php +++ b/src/Plugin/Derivative/FieldBlock.php @@ -9,17 +9,30 @@ namespace Drupal\fieldblock\Plugin\Derivative; use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Core\Entity\Entity\EntityViewDisplay; +use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides block plugin definitions for fieldblock blocks. * * @see \Drupal\fieldblock\Plugin\Block\FieldBlock */ -class FieldBlock extends DeriverBase { +class FieldBlock extends DeriverBase implements ContainerDeriverInterface { use StringTranslationTrait; + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, $base_plugin_id) { + $foo = 'bar'; + return new static( + $base_plugin_id, + $container->get('string_translation') + ); + } + /** * {@inheritdoc} */ @@ -55,7 +68,7 @@ class FieldBlock extends DeriverBase { foreach ($view_display_fieldblocks as $field_name => $field_label) { $fieldblock_id = $display_id . ':' . $field_name; - $fieldblocks[$fieldblock_id] = t('@field field (from @type: @bundle: @mode)', array( + $fieldblocks[$fieldblock_id] = $this->t('@field field (from @type: @bundle: @mode)', array( '@field' => $field_label, '@type' => $entity_type, '@bundle' => $bundle, -- GitLab