From deebed44b27deeea26d516c277c7e8f985637857 Mon Sep 17 00:00:00 2001 From: webchick Date: Wed, 18 Sep 2013 18:48:18 -0700 Subject: [PATCH] Issue #2087231 by tim.plunkett, pwolanin: Add a PluginBase in the Core namespace with t() as a helper method. --- core/lib/Drupal/Core/Action/ActionBase.php | 2 +- core/lib/Drupal/Core/Menu/LocalActionBase.php | 2 +- .../lib/Drupal/Core/Menu/LocalTaskDefault.php | 2 +- core/lib/Drupal/Core/Plugin/PluginBase.php | 61 +++++++++++++++++++ .../Plugin/AggregatorPluginSettingsBase.php | 2 +- .../block/lib/Drupal/block/BlockBase.php | 6 +- .../Drupal/ckeditor/CKEditorPluginBase.php | 2 +- .../edit/lib/Drupal/edit/EditorBase.php | 2 +- .../lib/Drupal/editor/Plugin/EditorBase.php | 2 +- .../field/Plugin/PluginSettingsBase.php | 2 +- .../lib/Drupal/filter/Plugin/FilterBase.php | 2 +- .../lib/Drupal/image/ImageEffectBase.php | 2 +- .../lib/Drupal/rest/Plugin/ResourceBase.php | 2 +- .../Drupal/search/Plugin/SearchPluginBase.php | 2 +- .../system/Plugin/ImageToolkit/GDToolkit.php | 2 +- .../Plugin/ImageToolkit/TestToolkit.php | 2 +- .../tour/lib/Drupal/tour/TipPluginBase.php | 2 +- .../Drupal/views/Plugin/views/PluginBase.php | 2 +- .../Plugin/views/join/JoinPluginBase.php | 2 +- 19 files changed, 81 insertions(+), 20 deletions(-) create mode 100644 core/lib/Drupal/Core/Plugin/PluginBase.php diff --git a/core/lib/Drupal/Core/Action/ActionBase.php b/core/lib/Drupal/Core/Action/ActionBase.php index 11f2042add1b..136fbb7da9d9 100644 --- a/core/lib/Drupal/Core/Action/ActionBase.php +++ b/core/lib/Drupal/Core/Action/ActionBase.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Action; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Action\ActionInterface; /** diff --git a/core/lib/Drupal/Core/Menu/LocalActionBase.php b/core/lib/Drupal/Core/Menu/LocalActionBase.php index e1eba91d94ca..c99fd78e4702 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionBase.php +++ b/core/lib/Drupal/Core/Menu/LocalActionBase.php @@ -7,9 +7,9 @@ namespace Drupal\Core\Menu; -use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Menu\LocalActionInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Plugin\PluginBase; use Drupal\Core\StringTranslation\Translator\TranslatorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; diff --git a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php index 5021e90450c0..766b600f4f97 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php @@ -7,8 +7,8 @@ namespace Drupal\Core\Menu; -use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Plugin\PluginBase; use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; diff --git a/core/lib/Drupal/Core/Plugin/PluginBase.php b/core/lib/Drupal/Core/Plugin/PluginBase.php new file mode 100644 index 000000000000..03f952a6426d --- /dev/null +++ b/core/lib/Drupal/Core/Plugin/PluginBase.php @@ -0,0 +1,61 @@ +translationManager()->translate($string, $args, $options); + } + + /** + * Gets the translation manager. + * + * @return \Drupal\Core\StringTranslation\TranslationInterface + * The translation manager. + */ + protected function translationManager() { + if (!$this->translationManager) { + $this->translationManager = \Drupal::getContainer()->get('string_translation'); + } + return $this->translationManager; + } + + /** + * Sets the translation manager for this plugin. + * + * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * The translation manager. + * + * @return self + * The plugin object. + */ + public function setTranslationManager(TranslationInterface $translation_manager) { + $this->translationManager = $translation_manager; + return $this; + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginSettingsBase.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginSettingsBase.php index 678cfaff27fa..9ca7c79efd30 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginSettingsBase.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginSettingsBase.php @@ -8,7 +8,7 @@ namespace Drupal\aggregator\Plugin; use Drupal\Component\Plugin\ConfigurablePluginInterface; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Plugin\PluginFormInterface; /** diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index 7888b7b15179..579e841ffe06 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -7,7 +7,7 @@ namespace Drupal\block; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\block\BlockInterface; use Drupal\Component\Utility\Unicode; use Drupal\Core\Language\Language; @@ -91,14 +91,14 @@ abstract class BlockBase extends PluginBase implements BlockPluginInterface { $form['label'] = array( '#type' => 'textfield', - '#title' => t('Title'), + '#title' => $this->t('Title'), '#maxlength' => 255, '#default_value' => !empty($this->configuration['label']) ? $this->configuration['label'] : $definition['admin_label'], '#required' => TRUE, ); $form['label_display'] = array( '#type' => 'checkbox', - '#title' => t('Display title'), + '#title' => $this->t('Display title'), '#default_value' => $this->configuration['label_display'] == BlockInterface::BLOCK_LABEL_VISIBLE, '#return_value' => BlockInterface::BLOCK_LABEL_VISIBLE, ); diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginBase.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginBase.php index 05e6b0db271e..1539db56de55 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginBase.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginBase.php @@ -7,7 +7,7 @@ namespace Drupal\ckeditor; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\editor\Entity\Editor; /** diff --git a/core/modules/edit/lib/Drupal/edit/EditorBase.php b/core/modules/edit/lib/Drupal/edit/EditorBase.php index 10b2f028ed94..c10435d765dc 100644 --- a/core/modules/edit/lib/Drupal/edit/EditorBase.php +++ b/core/modules/edit/lib/Drupal/edit/EditorBase.php @@ -7,7 +7,7 @@ namespace Drupal\edit; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\edit\EditPluginInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; diff --git a/core/modules/editor/lib/Drupal/editor/Plugin/EditorBase.php b/core/modules/editor/lib/Drupal/editor/Plugin/EditorBase.php index eabb3e1b6dab..4301d34da37f 100644 --- a/core/modules/editor/lib/Drupal/editor/Plugin/EditorBase.php +++ b/core/modules/editor/lib/Drupal/editor/Plugin/EditorBase.php @@ -7,7 +7,7 @@ namespace Drupal\editor\Plugin; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\editor\Entity\Editor; use Drupal\editor\Plugin\EditorPluginInterface; diff --git a/core/modules/field/lib/Drupal/field/Plugin/PluginSettingsBase.php b/core/modules/field/lib/Drupal/field/Plugin/PluginSettingsBase.php index 06f72e9597ea..345e70122553 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/PluginSettingsBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/PluginSettingsBase.php @@ -7,7 +7,7 @@ namespace Drupal\field\Plugin; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\field\Plugin\PluginSettingsInterface; /** diff --git a/core/modules/filter/lib/Drupal/filter/Plugin/FilterBase.php b/core/modules/filter/lib/Drupal/filter/Plugin/FilterBase.php index dede3d3bb2d8..6717ecdd0b99 100644 --- a/core/modules/filter/lib/Drupal/filter/Plugin/FilterBase.php +++ b/core/modules/filter/lib/Drupal/filter/Plugin/FilterBase.php @@ -7,7 +7,7 @@ namespace Drupal\filter\Plugin; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; /** * Provides a base class for Filter plugins. diff --git a/core/modules/image/lib/Drupal/image/ImageEffectBase.php b/core/modules/image/lib/Drupal/image/ImageEffectBase.php index 546a53f77c67..e9152065d255 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectBase.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectBase.php @@ -7,7 +7,7 @@ namespace Drupal\image; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; /** * Provides a base class for image effects. diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/ResourceBase.php b/core/modules/rest/lib/Drupal/rest/Plugin/ResourceBase.php index 3c1e9f944f23..413cd8d1a16b 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/ResourceBase.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/ResourceBase.php @@ -7,8 +7,8 @@ namespace Drupal\rest\Plugin; -use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Plugin\PluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; diff --git a/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php b/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php index 3b2b162eaab6..5a42d9d13d36 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php +++ b/core/modules/search/lib/Drupal/search/Plugin/SearchPluginBase.php @@ -7,7 +7,7 @@ namespace Drupal\search\Plugin; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; /** diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php index 3219edb8190d..486afa12a2ca 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php @@ -7,7 +7,7 @@ namespace Drupal\system\Plugin\ImageToolkit; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\system\Annotation\ImageToolkit; use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php index eede36a4fbc5..d8ae884ec30f 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php @@ -7,7 +7,7 @@ namespace Drupal\image_test\Plugin\ImageToolkit; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\system\Annotation\ImageToolkit; use Drupal\Core\Annotation\Translation; use Drupal\Core\Image\ImageInterface; diff --git a/core/modules/tour/lib/Drupal/tour/TipPluginBase.php b/core/modules/tour/lib/Drupal/tour/TipPluginBase.php index a77e3f5924b2..a35f9314e080 100644 --- a/core/modules/tour/lib/Drupal/tour/TipPluginBase.php +++ b/core/modules/tour/lib/Drupal/tour/TipPluginBase.php @@ -7,7 +7,7 @@ namespace Drupal\tour; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; use Drupal\tour\TipPluginInterface; /** diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php index a626c3ba50ff..a261315b7892 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/PluginBase.php @@ -7,8 +7,8 @@ namespace Drupal\views\Plugin\views; -use Drupal\Component\Plugin\PluginBase as ComponentPluginBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Plugin\PluginBase as ComponentPluginBase; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php index f97d08e1f403..ca8d3fe304a1 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/join/JoinPluginBase.php @@ -7,7 +7,7 @@ namespace Drupal\views\Plugin\views\join; -use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Plugin\PluginBase; /** * @defgroup views_join_handlers Views join handlers