diff --git a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php index 44233e8..b6958f4 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php @@ -141,7 +141,7 @@ public function getTitle() { 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 6a7c8af..032a1c1 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php @@ -186,21 +186,34 @@ public function testGetRouteParametersForDynamicRouteWithUpcastedParameters() { */ 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, ), ); } @@ -212,8 +225,9 @@ public function providerTestGetWeight() { * * @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());