diff --git a/core/core.services.yml b/core/core.services.yml index c3021b6..ce9c672 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -421,7 +421,7 @@ services: - { name: event_subscriber } controller.page: class: Drupal\Core\Controller\HtmlPageController - arguments: ['@controller_resolver', '@string_translation', '@title_resolver'] + arguments: ['@controller_resolver', '@title_resolver'] controller.ajax: class: Drupal\Core\Controller\AjaxController arguments: ['@controller_resolver', '@ajax_response_renderer'] @@ -549,7 +549,7 @@ services: arguments: ['@config.manager', '@config.storage', '@config.storage.snapshot'] exception_controller: class: Drupal\Core\Controller\ExceptionController - arguments: ['@content_negotiation', '@string_translation', '@title_resolver', '@html_page_renderer', '@html_fragment_renderer'] + arguments: ['@content_negotiation', '@title_resolver', '@html_page_renderer', '@html_fragment_renderer'] calls: - [setContainer, ['@service_container']] exception_listener: diff --git a/core/lib/Drupal/Core/Controller/ExceptionController.php b/core/lib/Drupal/Core/Controller/ExceptionController.php index d79567c..6e76617 100644 --- a/core/lib/Drupal/Core/Controller/ExceptionController.php +++ b/core/lib/Drupal/Core/Controller/ExceptionController.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Controller; use Drupal\Core\Page\HtmlPageRendererInterface; -use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -59,8 +58,6 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn * @param \Drupal\Core\ContentNegotiation $negotiation * The content negotiation library to use to determine the correct response * format. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver * The title resolver. * @param \Drupal\Core\Page\HtmlPageRendererInterface $renderer @@ -68,8 +65,8 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn * @param \Drupal\Core\Page\HtmlFragmentRendererInterface $fragment_renderer * The fragment rendering service. */ - public function __construct(ContentNegotiation $negotiation, TranslationInterface $translation_manager, TitleResolverInterface $title_resolver, HtmlPageRendererInterface $renderer, $fragment_renderer) { - parent::__construct($translation_manager, $title_resolver); + public function __construct(ContentNegotiation $negotiation, TitleResolverInterface $title_resolver, HtmlPageRendererInterface $renderer, $fragment_renderer) { + parent::__construct($title_resolver); $this->negotiation = $negotiation; $this->htmlPageRenderer = $renderer; $this->fragmentRenderer = $fragment_renderer; diff --git a/core/lib/Drupal/Core/Controller/HtmlControllerBase.php b/core/lib/Drupal/Core/Controller/HtmlControllerBase.php index 0204bc0..6d71b79 100644 --- a/core/lib/Drupal/Core/Controller/HtmlControllerBase.php +++ b/core/lib/Drupal/Core/Controller/HtmlControllerBase.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Controller; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Page\HtmlFragment; use Drupal\Core\Utility\Title; use Symfony\Cmf\Component\Routing\RouteObjectInterface; @@ -20,13 +19,6 @@ class HtmlControllerBase { /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * The title resolver. * * @var \Drupal\Core\Controller\TitleResolver @@ -36,13 +28,10 @@ class HtmlControllerBase { /** * Constructs a new HtmlControllerBase object. * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver * The title resolver. */ - public function __construct(TranslationInterface $translation_manager, TitleResolverInterface $title_resolver) { - $this->translationManager = $translation_manager; + public function __construct(TitleResolverInterface $title_resolver) { $this->titleResolver = $title_resolver; } diff --git a/core/lib/Drupal/Core/Controller/HtmlPageController.php b/core/lib/Drupal/Core/Controller/HtmlPageController.php index 1672939..6ed82f1 100644 --- a/core/lib/Drupal/Core/Controller/HtmlPageController.php +++ b/core/lib/Drupal/Core/Controller/HtmlPageController.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Controller; -use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -27,13 +26,11 @@ class HtmlPageController extends HtmlControllerBase { * * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver * The controller resolver. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver * The title resolver. */ - public function __construct(ControllerResolverInterface $controller_resolver, TranslationInterface $translation_manager, TitleResolverInterface $title_resolver) { - parent::__construct($translation_manager, $title_resolver); + public function __construct(ControllerResolverInterface $controller_resolver, TitleResolverInterface $title_resolver) { + parent::__construct($title_resolver); $this->controllerResolver = $controller_resolver; } diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php index e63679b..0e025e5 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php @@ -154,14 +154,14 @@ public function validate(array $form, array &$form_state); public function submit(array $form, array &$form_state); /** - * Sets the translation manager for this form. + * Sets the string translation service for this form. * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The translation manager. * * @return $this */ - public function setTranslationManager(TranslationInterface $translation_manager); + public function setStringTranslation(TranslationInterface $string_translation); /** * Sets the module handler for this form. diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 5684a9d..f639517 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -213,7 +213,7 @@ public function getFormController($entity_type, $operation) { } $controller - ->setTranslationManager($this->translationManager) + ->setStringTranslation($this->translationManager) ->setModuleHandler($this->moduleHandler) ->setOperation($operation); $this->controllers['form'][$operation][$entity_type] = $controller; @@ -271,8 +271,8 @@ public function getController($entity_type, $controller_type, $controller_class_ if (method_exists($controller, 'setModuleHandler')) { $controller->setModuleHandler($this->moduleHandler); } - if (method_exists($controller, 'setTranslationManager')) { - $controller->setTranslationManager($this->translationManager); + if (method_exists($controller, 'setStringTranslation')) { + $controller->setStringTranslation($this->translationManager); } $this->controllers[$controller_type][$entity_type] = $controller; } diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 49edc7c..2230fb3 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -125,19 +125,19 @@ class FormBuilder implements FormBuilderInterface { * The event dispatcher. * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * The URL generator. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * 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, KeyValueExpirableFactoryInterface $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, KeyValueExpirableFactoryInterface $key_value_expirable_factory, EventDispatcherInterface $event_dispatcher, UrlGeneratorInterface $url_generator, TranslationInterface $string_translation, 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->stringTranslation = $string_translation; $this->csrfToken = $csrf_token; $this->httpKernel = $http_kernel; } diff --git a/core/modules/config_translation/lib/Drupal/config_translation/ConfigNamesMapper.php b/core/modules/config_translation/lib/Drupal/config_translation/ConfigNamesMapper.php index 8198a47..d02f7a9 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/ConfigNamesMapper.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/ConfigNamesMapper.php @@ -81,14 +81,14 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con * The mapper plugin discovery service. * @param \Drupal\Core\Routing\RouteProviderInterface * The route provider. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation manager. * * @throws \Symfony\Component\Routing\Exception\RouteNotFoundException * Throws an exception if the route specified by the 'base_route_name' in * the plugin definition could not be found by the route provider. */ - public function __construct($plugin_id, array $plugin_definition, ConfigFactoryInterface $config_factory, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $translation_manager) { + public function __construct($plugin_id, array $plugin_definition, ConfigFactoryInterface $config_factory, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $string_translation) { $this->pluginId = $plugin_id; $this->pluginDefinition = $plugin_definition; @@ -96,7 +96,7 @@ public function __construct($plugin_id, array $plugin_definition, ConfigFactoryI $this->localeConfigManager = $locale_config_manager; $this->configMapperManager = $config_mapper_manager; - $this->setTranslationManager($translation_manager); + $this->stringTranslation = $string_translation; $this->baseRoute = $route_provider->getRouteByName($this->getBaseRouteName()); } diff --git a/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecutableTest.php b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecutableTest.php index cd54fd9..f825287 100644 --- a/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecutableTest.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecutableTest.php @@ -71,7 +71,7 @@ protected function setUp() { $this->message = $this->getMock('Drupal\migrate\MigrateMessageInterface'); $this->executable = new TestMigrateExecutable($this->migration, $this->message); - $this->executable->setTranslationManager($this->getStringTranslationStub()); + $this->executable->setStringTranslation($this->getStringTranslationStub()); } /** diff --git a/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecuteableMemoryExceededTest.php b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecuteableMemoryExceededTest.php index d69873f..b14069a 100644 --- a/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecuteableMemoryExceededTest.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecuteableMemoryExceededTest.php @@ -77,7 +77,7 @@ protected function setUp() { $this->message = $this->getMock('Drupal\migrate\MigrateMessageInterface'); $this->executable = new TestMigrateExecutable($this->migration, $this->message); - $this->executable->setTranslationManager($this->getStringTranslationStub()); + $this->executable->setStringTranslation($this->getStringTranslationStub()); } /** diff --git a/core/modules/migrate/tests/Drupal/migrate/Tests/TestMigrateExecutable.php b/core/modules/migrate/tests/Drupal/migrate/Tests/TestMigrateExecutable.php index 1a222c7..2ceaff1 100644 --- a/core/modules/migrate/tests/Drupal/migrate/Tests/TestMigrateExecutable.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/TestMigrateExecutable.php @@ -37,13 +37,13 @@ class TestMigrateExecutable extends MigrateExecutable { protected $clearedMemoryUsage; /** - * Sets the translation manager. + * Sets the string translation service. * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The translation manager. */ - public function setTranslationManager(TranslationInterface $translation_manager) { - $this->translationManager = $translation_manager; + public function setStringTranslation(TranslationInterface $string_translation) { + $this->stringTranslation = $string_translation; } /** diff --git a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php index 534f824..43977c9 100644 --- a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php +++ b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php @@ -125,7 +125,7 @@ public function testBuildRowEntityList() { // because t() is called on there. $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); $view_list_controller = new TestViewListController($entity_type, $storage_controller, $display_manager); - $view_list_controller->setTranslationManager($this->getStringTranslationStub()); + $view_list_controller->setStringTranslation($this->getStringTranslationStub()); $view = new View($values, 'view'); diff --git a/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php index 0c5f4e7..7597dea 100644 --- a/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php @@ -35,7 +35,6 @@ public static function getInfo() { public function test405HTML() { $exception = new \Exception('Test exception'); $flat_exception = FlattenException::create($exception, 405); - $translation_manager = $this->getStringTranslationStub(); $html_page_renderer = $this->getMock('Drupal\Core\Page\HtmlPageRendererInterface'); $html_fragment_renderer = $this->getMock('Drupal\Core\Page\HtmlFragmentRendererInterface'); $title_resolver = $this->getMock('Drupal\Core\Controller\TitleResolverInterface'); @@ -45,7 +44,7 @@ public function test405HTML() { ->method('getContentType') ->will($this->returnValue('html')); - $exception_controller = new ExceptionController($content_negotiation, $translation_manager, $title_resolver, $html_page_renderer, $html_fragment_renderer); + $exception_controller = new ExceptionController($content_negotiation, $title_resolver, $html_page_renderer, $html_fragment_renderer); $response = $exception_controller->execute($flat_exception, new Request()); $this->assertEquals($response->getStatusCode(), 405, 'HTTP status of response is correct.'); $this->assertEquals($response->getContent(), 'Method Not Allowed', 'HTTP response body is correct.'); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index eaae25a..aaabaa0 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -347,7 +347,7 @@ public function testGetFormController() { $apple_form = $this->entityManager->getFormController('apple', 'default'); $this->assertInstanceOf('Drupal\Tests\Core\Entity\TestEntityForm', $apple_form); $this->assertAttributeInstanceOf('Drupal\Core\Extension\ModuleHandlerInterface', 'moduleHandler', $apple_form); - $this->assertAttributeInstanceOf('Drupal\Core\StringTranslation\TranslationInterface', 'translationManager', $apple_form); + $this->assertAttributeInstanceOf('Drupal\Core\StringTranslation\TranslationInterface', 'stringTranslation', $apple_form); $banana_form = $this->entityManager->getFormController('banana', 'default'); $this->assertInstanceOf('Drupal\Tests\Core\Entity\TestEntityFormInjected', $banana_form); @@ -397,7 +397,7 @@ public function testGetController() { $apple_controller = $this->entityManager->getController('apple', 'storage'); $this->assertInstanceOf($class, $apple_controller); $this->assertAttributeInstanceOf('Drupal\Core\Extension\ModuleHandlerInterface', 'moduleHandler', $apple_controller); - $this->assertAttributeInstanceOf('Drupal\Core\StringTranslation\TranslationInterface', 'translationManager', $apple_controller); + $this->assertAttributeInstanceOf('Drupal\Core\StringTranslation\TranslationInterface', 'stringTranslation', $apple_controller); $banana_controller = $this->entityManager->getController('banana', 'storage', 'getStorageClass'); $this->assertInstanceOf('Drupal\Tests\Core\Entity\TestEntityControllerInjected', $banana_controller); diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php index e93b127..4603bdc 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php @@ -71,7 +71,7 @@ protected function setUp() { protected function setupContextualLinkDefault() { $this->contextualLinkDefault = new ContextualLinkDefault($this->config, $this->pluginId, $this->pluginDefinition); - $this->contextualLinkDefault->setTranslationManager($this->stringTranslation); + $this->contextualLinkDefault->setStringTranslation($this->stringTranslation); } /** diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php index 2ce3cf5..8478faa 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php @@ -81,7 +81,7 @@ protected function setUp() { */ protected function setupLocalActionDefault() { $this->localActionDefault = new LocalActionDefault($this->config, $this->pluginId, $this->pluginDefinition, $this->routeProvider); - $this->localActionDefault->setTranslationManager($this->stringTranslation); + $this->localActionDefault->setStringTranslation($this->stringTranslation); } /** diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php index 26ea046..c338878 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php @@ -87,7 +87,7 @@ protected function setupLocalTaskDefault() { $this->localTaskBase = new TestLocalTaskDefault($this->config, $this->pluginId, $this->pluginDefinition); $this->localTaskBase ->setRouteProvider($this->routeProvider) - ->setTranslationManager($this->stringTranslation); + ->setStringTranslation($this->stringTranslation); } diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitMock.php b/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitMock.php deleted file mode 100644 index 1cfb280..0000000 --- a/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitMock.php +++ /dev/null @@ -1,19 +0,0 @@ - 'String translation trait', @@ -28,13 +45,33 @@ public static function getInfo() { ); } + /** + * {@inheritdoc} + */ + public function setUp() { + $this->translation = $this->getObjectForTrait('\Drupal\Core\StringTranslation\StringTranslationTrait'); + $this->translation->setStringTranslation($this->getStringTranslationStub()); + $this->reflection = new \ReflectionClass(get_class($this->translation)); + } + + /** + * Tests \Drupal\Core\StringTranslation\StringTranslationTrait::t() + */ public function testT() { - $method = (new \ReflectionClass('\Drupal\Tests\Core\StringTranslation\StringTranslationTraitMock'))->getMethod('t'); + $method = $this->reflection->getMethod('t'); + $method->setAccessible(TRUE); + + $this->assertEquals('something', $method->invoke($this->translation, 'something')); + } + + /** + * Tests \Drupal\Core\StringTranslation\StringTranslationTrait::formatPlural() + */ + public function testFormatPlural() { + $method = $this->reflection->getMethod('formatPlural'); $method->setAccessible(TRUE); - $translation = new StringTranslationTraitMock(); - $translation->setTranslationManager($this->getStringTranslationStub()); - $this->assertEquals('something', $method->invoke($translation, 'something')); + $this->assertEquals(NULL, $method->invoke($this->translation, rand(0, 10), '', '')); } }