diff --git a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php index 86b7c9b..fc804b1 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php @@ -23,7 +23,7 @@ class LocalTaskDefault extends PluginBase implements LocalTaskInterface, Contain * * @var \Drupal\Core\StringTranslation\Translator\TranslatorInterface */ - protected $t; + protected $stringTranslation; /** * URL generator object. @@ -55,7 +55,7 @@ class LocalTaskDefault extends PluginBase implements LocalTaskInterface, Contain */ public function __construct(array $configuration, $plugin_id, array $plugin_definition, TranslatorInterface $string_translation, UrlGeneratorInterface $generator) { // This is available for subclasses that need to translate a dynamic title. - $this->t = $string_translation; + $this->stringTranslation = $string_translation; $this->generator = $generator; parent::__construct($configuration, $plugin_id, $plugin_definition); } @@ -74,6 +74,29 @@ public static function create(ContainerInterface $container, array $configuratio } /** + * Translates a string to the current language or to a given language using + * the string translation service. + * + * @param string $string + * A string containing the English string to translate. + * @param array $args + * An associative array of replacements to make after translation. Based + * on the first character of the key, the value is escaped and/or themed. + * See \Drupal\Core\Utility\String::format() for details. + * @param array $options + * An associative array of additional options, with the following elements: + * - 'langcode': The language code to translate to a language other than + * what is used to display the page. + * - 'context': The context the source string belongs to. + * + * @return string + * The translated string. + */ + protected function t($string, array $args = array(), array $options = array()) { + return $this->stringTranslation->translate($string, $args, $options); + } + + /** * {@inheritdoc} */ public function getRouteName() { @@ -85,7 +108,7 @@ public function getRouteName() { */ public function getTitle() { // Subclasses may pull in the request or specific attributes as parameters. - return $this->t->translate($this->pluginDefinition['title']); + return $this->t($this->pluginDefinition['title']); } /** diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index cd4bed5..0dad7f3 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -109,7 +109,7 @@ public function __construct(ControllerResolverInterface $controller_resolver, Re * {@inheritdoc} */ public function processDefinition(&$definition, $plugin_id) { - $definition += $this->defaults; + parent::processDefinition($definition, $plugin_id); // If there is no route name, this is a broken definition. if (empty($definition['route_name'])) { throw new PluginException(sprintf('Plugin (%s) definition must include "route_name"', $plugin_id)); diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/LocalTasksTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/LocalTasksTest.php index d3e481a..91d68f9 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/LocalTasksTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/LocalTasksTest.php @@ -183,7 +183,7 @@ public function testPluginLocalTask() { $result = $this->xpath('//ul[contains(@class, "tabs")]//a[contains(@class, "active")]'); $this->assertEqual(2, count($result), 'There are tabs active on both levels.'); $this->assertEqual('Settings', (string) $result[0], 'The settings tab is active.'); - $this->assertEqual('Dynamic title', (string) $result[1], 'The sub1 tab is active.'); + $this->assertEqual('Dynamic title for TestTasksSettingsSub1', (string) $result[1], 'The sub1 tab is active.'); } } diff --git a/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/Plugin/Menu/LocalTask/TestTasksSettingsSub1.php b/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/Plugin/Menu/LocalTask/TestTasksSettingsSub1.php index 25f758c..ebe8818 100644 --- a/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/Plugin/Menu/LocalTask/TestTasksSettingsSub1.php +++ b/core/modules/system/tests/modules/menu_test/lib/Drupal/menu_test/Plugin/Menu/LocalTask/TestTasksSettingsSub1.php @@ -17,7 +17,7 @@ class TestTasksSettingsSub1 extends LocalTaskDefault { * {@inheritdoc} */ function getTitle() { - return 'Dynamic title'; + return $this->t('Dynamic title for @class', array('@class' => 'TestTasksSettingsSub1')); } } diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index 8ac918d..c19cf28 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -293,6 +293,17 @@ protected function getLocalTaskFixtures() { 'tab_root_id' => 'menu_local_task_test_tasks_view', 'class' => 'Drupal\menu_test\Plugin\Menu\MenuLocalTasksTestTasksView', ); + // Add the defaults from the LocalTaskManager. + foreach ($definitions as $id => &$info) { + $info += array( + 'title' => '', + 'tab_root_id' => '', + 'tab_parent_id' => NULL, + 'weight' => 0, + 'options' => array(), + 'class' => 'Drupal\Core\Menu\LocalTaskDefault', + ); + } return $definitions; }