diff --git a/core/core.services.yml b/core/core.services.yml index 0ea69d4..a795997 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -384,7 +384,7 @@ services: - { name: event_subscriber } controller.page: class: Drupal\Core\Controller\HtmlPageController - arguments: ['@http_kernel', '@controller_resolver', '@string_translation', '@title_resolver'] + arguments: ['@http_kernel', '@controller_resolver', '@title_resolver'] controller.dialog: class: Drupal\Core\Controller\DialogController arguments: ['@http_kernel', '@title_resolver'] diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php index 63fe199..2061132 100644 --- a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php @@ -7,13 +7,15 @@ namespace Drupal\Core\Breadcrumb; +use Drupal\Core\StringTranslation\StringTranslationTrait; + /** * Defines a common base class for breadcrumb builders adding a link generator. - * - * @todo Use traits once we have a PHP 5.4 requirement. */ abstract class BreadcrumbBuilderBase implements BreadcrumbBuilderInterface { + use StringTranslationTrait; + /** * The link generator. * @@ -22,13 +24,6 @@ protected $linkGenerator; /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Returns the service container. * * @return \Symfony\Component\DependencyInjection\ContainerInterface $container @@ -64,26 +59,4 @@ protected function linkGenerator() { return $this->linkGenerator; } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager()->translate($string, $args, $options); - } - - /** - * Returns the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = $this->container()->get('string_translation'); - } - return $this->translationManager; - } - } diff --git a/core/lib/Drupal/Core/Controller/ControllerBase.php b/core/lib/Drupal/Core/Controller/ControllerBase.php index 618bfee..a0379a4 100644 --- a/core/lib/Drupal/Core/Controller/ControllerBase.php +++ b/core/lib/Drupal/Core/Controller/ControllerBase.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Controller; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\HttpFoundation\RedirectResponse; /** @@ -30,6 +31,8 @@ */ abstract class ControllerBase { + use StringTranslationTrait; + /** * The entity manager. * @@ -45,13 +48,6 @@ protected $languageManager; /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * The configuration factory. * * @var \Drupal\Core\Config\Config @@ -228,28 +224,6 @@ protected function currentUser() { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager()->translate($string, $args, $options); - } - - /** - * Returns the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = $this->container()->get('string_translation'); - } - return $this->translationManager; - } - - /** * Returns the language manager service. * * @return \Drupal\Core\Language\LanguageManager diff --git a/core/lib/Drupal/Core/Controller/HtmlPageController.php b/core/lib/Drupal/Core/Controller/HtmlPageController.php index f3358ad..2fffa6e 100644 --- a/core/lib/Drupal/Core/Controller/HtmlPageController.php +++ b/core/lib/Drupal/Core/Controller/HtmlPageController.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Controller; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -18,6 +18,8 @@ */ class HtmlPageController { + use StringTranslationTrait; + /** * The HttpKernel object to use for subrequests. * @@ -33,13 +35,6 @@ class HtmlPageController { protected $controllerResolver; /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * The title resolver. * * @var \Drupal\Core\Controller\TitleResolver @@ -52,15 +47,12 @@ class HtmlPageController { * @param \Symfony\Component\HttpKernel\HttpKernelInterface $kernel * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver * The controller resolver. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. * @param \Drupal\Core\Controller\TitleResolver $title_resolver * The title resolver. */ - public function __construct(HttpKernelInterface $kernel, ControllerResolverInterface $controller_resolver, TranslationInterface $translation_manager, TitleResolver $title_resolver) { + public function __construct(HttpKernelInterface $kernel, ControllerResolverInterface $controller_resolver, TitleResolver $title_resolver) { $this->httpKernel = $kernel; $this->controllerResolver = $controller_resolver; - $this->translationManager = $translation_manager; $this->titleResolver = $title_resolver; } @@ -101,13 +93,4 @@ public function content(Request $request, $_content) { return $response; } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - } diff --git a/core/lib/Drupal/Core/Controller/TitleResolver.php b/core/lib/Drupal/Core/Controller/TitleResolver.php index 359af1d..6041627 100644 --- a/core/lib/Drupal/Core/Controller/TitleResolver.php +++ b/core/lib/Drupal/Core/Controller/TitleResolver.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Controller; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; @@ -16,6 +17,8 @@ */ class TitleResolver implements TitleResolverInterface { + use StringTranslationTrait; + /** * The controller resolver. * @@ -24,13 +27,6 @@ class TitleResolver implements TitleResolverInterface { protected $controllerResolver; /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Constructs a TitleResolver instance. * * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver @@ -62,7 +58,7 @@ public function getTitle(Request $request, Route $route) { $options['context'] = $context; } // Fall back to a static string from the route. - $route_title = $this->translationManager->translate($title, array(), $options); + $route_title = $this->t($title, array(), $options); } return $route_title; } diff --git a/core/lib/Drupal/Core/Entity/EntityListController.php b/core/lib/Drupal/Core/Entity/EntityListController.php index 0a722a0..27ac6de 100644 --- a/core/lib/Drupal/Core/Entity/EntityListController.php +++ b/core/lib/Drupal/Core/Entity/EntityListController.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Entity; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Component\Utility\String; @@ -17,6 +17,8 @@ */ class EntityListController implements EntityListControllerInterface, EntityControllerInterface { + use StringTranslationTrait; + /** * The entity storage controller class. * @@ -48,13 +50,6 @@ class EntityListController implements EntityListControllerInterface, EntityContr protected $entityInfo; /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * {@inheritdoc} */ public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { @@ -213,40 +208,4 @@ public function render() { return $build; } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->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::translation(); - } - return $this->translationManager; - } - - /** - * Sets the translation manager for this form. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. - * - * @return self - * The entity form. - */ - public function setTranslationManager(TranslationInterface $translation_manager) { - $this->translationManager = $translation_manager; - return $this; - } - } diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php index 2fad298..7decf48 100644 --- a/core/lib/Drupal/Core/Form/FormBase.php +++ b/core/lib/Drupal/Core/Form/FormBase.php @@ -11,7 +11,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\Routing\UrlGeneratorInterface; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -20,12 +20,7 @@ */ abstract class FormBase extends DependencySerialization implements FormInterface, ContainerInjectionInterface { - /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; + use StringTranslationTrait; /** * The current request. @@ -63,15 +58,6 @@ public function validateForm(array &$form, array &$form_state) { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager()->translate($string, $args, $options); - } - - /** * Generates a URL or path for a specific route based on the given parameters. * * @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for @@ -85,19 +71,6 @@ public function url($route_name, $route_parameters = array(), $options = array() } /** - * Gets the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = $this->container()->get('string_translation'); - } - return $this->translationManager; - } - - /** * Retrieves a configuration object. * * This is the main entry point to the configuration API. Calling @@ -121,20 +94,6 @@ protected function config($name) { } /** - * Sets the translation manager for this form. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. - * - * @return self - * The entity form. - */ - public function setTranslationManager(TranslationInterface $translation_manager) { - $this->translationManager = $translation_manager; - return $this; - } - - /** * Sets the config factory for this form. * * @param \Drupal\Core\Config\ConfigFactory $config_factory diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 38bfab7..6188a236 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -16,7 +16,7 @@ use Drupal\Core\HttpKernel; use Drupal\Core\KeyValueStore\KeyValueExpirableFactory; use Drupal\Core\Routing\UrlGeneratorInterface; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -30,6 +30,8 @@ */ class FormBuilder implements FormBuilderInterface { + use StringTranslationTrait; + /** * The module handler. * @@ -59,13 +61,6 @@ class FormBuilder implements FormBuilderInterface { protected $urlGenerator; /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * The current request. * * @var \Symfony\Component\HttpFoundation\Request @@ -135,19 +130,16 @@ class FormBuilder implements FormBuilderInterface { * The event dispatcher. * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * The URL generator. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. * @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token * The CSRF token generator. * @param \Drupal\Core\HttpKernel $http_kernel * The HTTP kernel. */ - public function __construct(ModuleHandlerInterface $module_handler, KeyValueExpirableFactory $key_value_expirable_factory, EventDispatcherInterface $event_dispatcher, UrlGeneratorInterface $url_generator, TranslationInterface $translation_manager, CsrfTokenGenerator $csrf_token = NULL, HttpKernel $http_kernel = NULL) { + public function __construct(ModuleHandlerInterface $module_handler, KeyValueExpirableFactory $key_value_expirable_factory, EventDispatcherInterface $event_dispatcher, UrlGeneratorInterface $url_generator, CsrfTokenGenerator $csrf_token = NULL, HttpKernel $http_kernel = NULL) { $this->moduleHandler = $module_handler; $this->keyValueExpirableFactory = $key_value_expirable_factory; $this->eventDispatcher = $event_dispatcher; $this->urlGenerator = $url_generator; - $this->translationManager = $translation_manager; $this->csrfToken = $csrf_token; $this->httpKernel = $http_kernel; } @@ -1778,15 +1770,6 @@ protected function currentUser() { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - - /** * {@inheritdoc} */ public function setRequest(Request $request) { diff --git a/core/lib/Drupal/Core/Plugin/PluginBase.php b/core/lib/Drupal/Core/Plugin/PluginBase.php index 03f952a..e55a69f 100644 --- a/core/lib/Drupal/Core/Plugin/PluginBase.php +++ b/core/lib/Drupal/Core/Plugin/PluginBase.php @@ -8,54 +8,13 @@ namespace Drupal\Core\Plugin; use Drupal\Component\Plugin\PluginBase as ComponentPluginBase; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Base class for plugins supporting metadata inspection and translation. */ abstract class PluginBase extends ComponentPluginBase { - /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->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; - } + use StringTranslationTrait; } diff --git a/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php b/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php new file mode 100644 index 0000000..7a53c68 --- /dev/null +++ b/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php @@ -0,0 +1,54 @@ +getTranslationManager()->translate($string, $args, $options); + } + + /** + * Gets the translation manager. + * + * @return \Drupal\Core\StringTranslation\TranslationInterface + * The translation manager. + */ + protected function getTranslationManager() { + if (!$this->translationManager) { + $this->translationManager = \Drupal::service('string_translation'); + } + return $this->translationManager; + } + + /** + * Sets the string translation service to use. + * + * @param \Drupal\Core\StringTranslation\TranslationInterface $translation + * The string translation service. + */ + public function setTranslationManager(TranslationInterface $translation) { + $this->translationManager = $translation; + } + +} diff --git a/core/modules/block/block.services.yml b/core/modules/block/block.services.yml index b6bf1f4..6e87ce2 100644 --- a/core/modules/block/block.services.yml +++ b/core/modules/block/block.services.yml @@ -1,7 +1,7 @@ services: plugin.manager.block: class: Drupal\block\Plugin\Type\BlockManager - arguments: ['@container.namespaces', '@cache.block', '@language_manager', '@module_handler', '@string_translation'] + arguments: ['@container.namespaces', '@cache.block', '@language_manager', '@module_handler'] cache.block: class: Drupal\Core\Cache\CacheBackendInterface tags: diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php index a1187a6..55c8680 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -11,7 +11,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Manages discovery and instantiation of block plugins. @@ -22,6 +22,8 @@ */ class BlockManager extends DefaultPluginManager { + use StringTranslationTrait; + /** * An array of all available modules and their data. * @@ -30,13 +32,6 @@ class BlockManager extends DefaultPluginManager { protected $moduleData; /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Constructs a new \Drupal\block\Plugin\Type\BlockManager object. * * @param \Traversable $namespaces @@ -48,15 +43,12 @@ class BlockManager extends DefaultPluginManager { * The language manager. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook with. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager) { + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { parent::__construct('Plugin/Block', $namespaces, 'Drupal\block\Annotation\Block'); $this->alterInfo($module_handler, 'block'); $this->setCacheBackend($cache_backend, $language_manager, 'block_plugins'); - $this->translationManager = $translation_manager; } /** @@ -99,15 +91,6 @@ protected function getModuleName($module) { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - - /** * Gets the names of all block categories. * * @return array diff --git a/core/modules/book/book.services.yml b/core/modules/book/book.services.yml index fa7c66c..9cb93bc 100644 --- a/core/modules/book/book.services.yml +++ b/core/modules/book/book.services.yml @@ -6,7 +6,7 @@ services: - { name: breadcrumb_builder, priority: 701 } book.manager: class: Drupal\book\BookManager - arguments: ['@database', '@entity.manager', '@string_translation', '@config.factory'] + arguments: ['@database', '@entity.manager', '@config.factory'] book.export: class: Drupal\book\BookExport arguments: ['@entity.manager'] diff --git a/core/modules/book/lib/Drupal/book/BookManager.php b/core/modules/book/lib/Drupal/book/BookManager.php index d246632..ad229be 100644 --- a/core/modules/book/lib/Drupal/book/BookManager.php +++ b/core/modules/book/lib/Drupal/book/BookManager.php @@ -10,7 +10,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Config\ConfigFactory; use Drupal\node\NodeInterface; @@ -19,6 +19,8 @@ */ class BookManager { + use StringTranslationTrait; + /** * Database Service Object. * @@ -34,13 +36,6 @@ class BookManager { protected $entityManager; /** - * The translation service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translation; - - /** * Config Factory Service Object. * * @var \Drupal\Core\Config\ConfigFactory @@ -57,10 +52,9 @@ class BookManager { /** * Constructs a BookManager object. */ - public function __construct(Connection $connection, EntityManagerInterface $entity_manager, TranslationInterface $translation, ConfigFactory $config_factory) { + public function __construct(Connection $connection, EntityManagerInterface $entity_manager, ConfigFactory $config_factory) { $this->connection = $connection; $this->entityManager = $entity_manager; - $this->translation = $translation; $this->configFactory = $config_factory; } @@ -334,15 +328,6 @@ public function updateOutline(NodeInterface $node) { return FALSE; } -/** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translation->translate($string, $args, $options); - } - /** * Generates the corresponding menu name from a book ID. * diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationLocalTasks.php b/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationLocalTasks.php index f7da9a7..e8d5bd6 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationLocalTasks.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationLocalTasks.php @@ -131,14 +131,4 @@ protected function getTaskFromRoute($route_name, &$local_tasks) { return $parent_local_task; } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - * - * @todo Move to derivative base. https://drupal.org/node/2112575 - */ - public function t($string, array $args = array(), array $options = array()) { - \Drupal::translation()->translate($string, $args, $options); - } } diff --git a/core/modules/forum/forum.services.yml b/core/modules/forum/forum.services.yml index 8ea4dac..6fe8ae4 100644 --- a/core/modules/forum/forum.services.yml +++ b/core/modules/forum/forum.services.yml @@ -1,7 +1,8 @@ services: forum_manager: class: Drupal\forum\ForumManager - arguments: ['@config.factory', '@plugin.manager.entity', '@database', '@field.info', '@string_translation'] + arguments: ['@config.factory', '@plugin.manager.entity', '@database', '@field.info'] + forum.breadcrumb: class: Drupal\forum\ForumBreadcrumbBuilder arguments: ['@entity.manager', '@config.factory', '@forum_manager'] diff --git a/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php b/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php index 2372e71..0fcb633 100644 --- a/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php +++ b/core/modules/forum/lib/Drupal/forum/Controller/ForumController.php @@ -8,10 +8,9 @@ namespace Drupal\forum\Controller; use Drupal\Core\Config\Config; -use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\forum\ForumManagerInterface; use Drupal\taxonomy\TermInterface; use Drupal\taxonomy\TermStorageControllerInterface; @@ -23,6 +22,8 @@ */ class ForumController implements ContainerInjectionInterface { + use StringTranslationTrait; + /** * Forum manager service. * @@ -59,13 +60,6 @@ class ForumController implements ContainerInjectionInterface { protected $termStorageController; /** - * Translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Constructs a ForumController object. * * @param \Drupal\Core\Config\Config $config @@ -78,16 +72,13 @@ class ForumController implements ContainerInjectionInterface { * Term storage controller. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager service. */ - public function __construct(Config $config, ForumManagerInterface $forum_manager, VocabularyStorageControllerInterface $vocabulary_storage_controller, TermStorageControllerInterface $term_storage_controller, EntityManagerInterface $entity_manager, TranslationInterface $translation_manager) { + public function __construct(Config $config, ForumManagerInterface $forum_manager, VocabularyStorageControllerInterface $vocabulary_storage_controller, TermStorageControllerInterface $term_storage_controller, EntityManagerInterface $entity_manager) { $this->config = $config; $this->forumManager = $forum_manager; $this->vocabularyStorageController = $vocabulary_storage_controller; $this->termStorageController = $term_storage_controller; $this->entityManager = $entity_manager; - $this->translationManager = $translation_manager; } /** @@ -99,8 +90,7 @@ public static function create(ContainerInterface $container) { $container->get('forum_manager'), $container->get('entity.manager')->getStorageController('taxonomy_vocabulary'), $container->get('entity.manager')->getStorageController('taxonomy_term'), - $container->get('entity.manager'), - $container->get('string_translation') + $container->get('entity.manager') ); } @@ -211,13 +201,4 @@ public function addContainer() { return $this->entityManager->getForm($taxonomy_term, 'container'); } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - } diff --git a/core/modules/forum/lib/Drupal/forum/ForumManager.php b/core/modules/forum/lib/Drupal/forum/ForumManager.php index cdf9a5e..1aa64d3 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumManager.php +++ b/core/modules/forum/lib/Drupal/forum/ForumManager.php @@ -10,7 +10,7 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\FieldInfo; use Drupal\node\NodeInterface; @@ -19,6 +19,8 @@ */ class ForumManager implements ForumManagerInterface { + use StringTranslationTrait; + /** * Forum sort order, newest first. */ @@ -103,13 +105,6 @@ class ForumManager implements ForumManagerInterface { protected $fieldInfo; /** - * Translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Constructs the forum manager service. * * @param \Drupal\Core\Config\ConfigFactory $config_factory @@ -120,15 +115,12 @@ class ForumManager implements ForumManagerInterface { * The current database connection. * @param \Drupal\field\FieldInfo $field_info * The field info service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager service. */ - public function __construct(ConfigFactory $config_factory, EntityManagerInterface $entity_manager, Connection $connection, FieldInfo $field_info, TranslationInterface $translation_manager) { + public function __construct(ConfigFactory $config_factory, EntityManagerInterface $entity_manager, Connection $connection, FieldInfo $field_info) { $this->configFactory = $config_factory; $this->entityManager = $entity_manager; $this->connection = $connection; $this->fieldInfo = $field_info; - $this->translationManager = $translation_manager; } /** @@ -550,13 +542,4 @@ public function updateIndex($nid) { } } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - } diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitMock.php b/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitMock.php new file mode 100644 index 0000000..1cfb280 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitMock.php @@ -0,0 +1,19 @@ + 'String translation trait', + 'description' => 'Tests the string translation trait.', + 'group' => 'StringTranslation', + ); + } + + public function testT() { + $method = (new \ReflectionClass('\Drupal\Tests\Core\StringTranslation\StringTranslationTraitMock'))->getMethod('t'); + $method->setAccessible(TRUE); + + $translation = new StringTranslationTraitMock(); + $translation->setTranslationManager($this->getStringTranslationStub()); + $this->assertEquals('something', $method->invoke($translation, 'something')); + } + +}