diff --git a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php index 1ba0c3e0e41..058de098192 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php @@ -88,7 +88,7 @@ class LocalTaskDefault extends PluginBase implements LocalTaskInterface { public function getWeight() { // By default the weight is 0, or -10 for the root tab. if (!isset($this->pluginDefinition['weight'])) { - if ($this->pluginDefinition['tab_root_id'] == $this->pluginDefinition['id']) { + if ($this->pluginDefinition['tab_root_id'] == $this->pluginId) { $this->pluginDefinition['weight'] = -10; } else { diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php index f7231bf3586..8cf9e962e80 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php @@ -191,21 +191,34 @@ class LocalTaskDefaultTest extends UnitTestCase { */ public function providerTestGetWeight() { return array( - array(array('weight' => 314), 314), + // Manually specify a weight, so this is used. + array(array('weight' => 314), 'test_id', 314), // Ensure that a default tab get a lower weight. array( array( 'tab_root_id' => 'local_task_default', 'id' => 'local_task_default' ), + 'local_task_default', -10 ), + // If the root ID is different to the ID of the tab, ignore it. array( array( 'tab_root_id' => 'local_task_example', 'id' => 'local_task_default' ), - 0 + 'local_task_default', + 0, + ), + // Ensure that a default tab of a derivative gets the default value. + array( + array( + 'tab_root_id' => 'local_task_derivative_default:example_id', + 'id' => 'local_task_derivative_default' + ), + 'local_task_derivative_default:example_id', + -10, ), ); } @@ -217,8 +230,9 @@ class LocalTaskDefaultTest extends UnitTestCase { * * @see \Drupal\Core\Menu\LocalTaskDefault::getWeight() */ - public function testGetWeight(array $plugin_definition, $expected_weight) { + public function testGetWeight(array $plugin_definition, $plugin_id, $expected_weight) { $this->pluginDefinition = $plugin_definition; + $this->pluginId = $plugin_id; $this->setupLocalTaskDefault(); $this->assertEquals($expected_weight, $this->localTaskBase->getWeight());