Issue #2927311 by DanielVeza, smustgrave, Gribnif, richard.thomas, larowlan: Contextual links are not sorted by weight, contrary to documentation
(cherry picked from commit fcc16f4990
)
merge-requests/3604/head
parent
8c76fe6dc3
commit
38937209db
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\contextual\Element;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\SortArray;
|
||||
use Drupal\Core\Render\Element\RenderElement;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
|
@ -72,6 +73,8 @@ class ContextualLinks extends RenderElement {
|
|||
$items += $contextual_links_manager->getContextualLinksArrayByGroup($group, $args['route_parameters'], $args['metadata']);
|
||||
}
|
||||
|
||||
uasort($items, [SortArray::class, 'sortByWeightElement']);
|
||||
|
||||
// Transform contextual links into parameters suitable for links.html.twig.
|
||||
$links = [];
|
||||
foreach ($items as $class => $item) {
|
||||
|
|
|
@ -161,6 +161,11 @@ class ContextualDynamicContextTest extends BrowserTestBase {
|
|||
$this->drupalGet(Url::fromRoute('menu_test.contextual_test'));
|
||||
$this->assertSession()->assertEscaped("<script>alert('Welcome to the jungle!')</script>");
|
||||
$this->assertSession()->responseContains('<li><a href="' . base_path() . 'menu-test-contextual/1/edit" class="use-ajax" data-dialog-type="modal" data-is-something>Edit menu - contextual</a></li>');
|
||||
// Test contextual links respects the weight set in *.links.contextual.yml.
|
||||
$firstLink = $this->assertSession()->elementExists('css', 'ul.contextual-links li:nth-of-type(1) a');
|
||||
$secondLink = $this->assertSession()->elementExists('css', 'ul.contextual-links li:nth-of-type(2) a');
|
||||
$this->assertEquals(base_path() . 'menu-test-contextual/1/edit', $firstLink->getAttribute('href'));
|
||||
$this->assertEquals(base_path() . 'menu-test-contextual/1', $secondLink->getAttribute('href'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@ menu_test.contextual_hidden_manage:
|
|||
group: menu_test_menu
|
||||
route_name: menu_test.contextual_hidden_manage
|
||||
class: '\Drupal\menu_test\Plugin\Menu\ContextualLink\TestContextualLink'
|
||||
weight: 2
|
||||
|
||||
menu_test.contextual_hidden_manage_edit:
|
||||
title: 'Edit menu - contextual'
|
||||
|
@ -13,8 +14,10 @@ menu_test.contextual_hidden_manage_edit:
|
|||
class: ['use-ajax']
|
||||
data-dialog-type: 'modal'
|
||||
data-is-something: TRUE
|
||||
weight: 1
|
||||
|
||||
menu_test.hidden_block_configure:
|
||||
title: 'Configure block'
|
||||
group: menu_test_block
|
||||
route_name: menu_test.hidden_block_configure
|
||||
weight: 0
|
||||
|
|
Loading…
Reference in New Issue