Skip to content
Snippets Groups Projects
Verified Commit 6ee5f78c authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #2852898 by smustgrave, _utsavsharma, mherchel, larowlan, bnjmnm,...

Issue #2852898 by smustgrave, _utsavsharma, mherchel, larowlan, bnjmnm, borisson_, kershme, DuaelFr: 508 Compliance Issue -Edit links on content page are not unique
parent 7393eba2
No related branches found
No related tags found
No related merge requests found
...@@ -142,13 +142,35 @@ public function getOperations(EntityInterface $entity) { ...@@ -142,13 +142,35 @@ public function getOperations(EntityInterface $entity) {
protected function getDefaultOperations(EntityInterface $entity) { protected function getDefaultOperations(EntityInterface $entity) {
$operations = []; $operations = [];
if ($entity->access('update') && $entity->hasLinkTemplate('edit-form')) { if ($entity->access('update') && $entity->hasLinkTemplate('edit-form')) {
$edit_url = $this->ensureDestination($entity->toUrl('edit-form'));
if (!empty($entity->label())) {
$label = $this->t('Edit @entity_label', ['@entity_label' => $entity->label()]);
}
else {
$label = $this->t('Edit @entity_bundle @entity_id', ['@entity_bundle' => $entity->bundle(), '@entity_id' => $entity->id()]);
}
$attributes = $edit_url->getOption('attributes') ?: [];
$attributes += ['aria-label' => $label];
$edit_url->setOption('attributes', $attributes);
$operations['edit'] = [ $operations['edit'] = [
'title' => $this->t('Edit'), 'title' => $this->t('Edit'),
'weight' => 10, 'weight' => 10,
'url' => $this->ensureDestination($entity->toUrl('edit-form')), 'url' => $edit_url,
]; ];
} }
if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) { if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) {
$delete_url = $this->ensureDestination($entity->toUrl('delete-form'));
if (!empty($entity->label())) {
$label = $this->t('Delete @entity_label', ['@entity_label' => $entity->label()]);
}
else {
$label = $this->t('Delete @entity_bundle @entity_id', ['@entity_bundle' => $entity->bundle(), '@entity_id' => $entity->id()]);
}
$attributes = $delete_url->getOption('attributes') ?: [];
$attributes += ['aria-label' => $label];
$delete_url->setOption('attributes', $attributes);
$operations['delete'] = [ $operations['delete'] = [
'title' => $this->t('Delete'), 'title' => $this->t('Delete'),
'weight' => 100, 'weight' => 100,
...@@ -159,7 +181,7 @@ protected function getDefaultOperations(EntityInterface $entity) { ...@@ -159,7 +181,7 @@ protected function getDefaultOperations(EntityInterface $entity) {
'width' => 880, 'width' => 880,
]), ]),
], ],
'url' => $this->ensureDestination($entity->toUrl('delete-form')), 'url' => $delete_url,
]; ];
} }
......
...@@ -58,11 +58,17 @@ public function testList() { ...@@ -58,11 +58,17 @@ public function testList() {
$this->assertInstanceOf(ConfigTest::class, $entity); $this->assertInstanceOf(ConfigTest::class, $entity);
// Test getOperations() method. // Test getOperations() method.
$edit_url = $entity->toUrl()->setOption('query', $this->getRedirectDestination()->getAsArray());
$edit_url->setOption('attributes', ['aria-label' => 'Edit ' . $entity->label()]);
$delete_url = $entity->toUrl('delete-form')->setOption('query', $this->getRedirectDestination()->getAsArray());
$delete_url->setOption('attributes', ['aria-label' => 'Delete ' . $entity->label()]);
$expected_operations = [ $expected_operations = [
'edit' => [ 'edit' => [
'title' => 'Edit', 'title' => 'Edit',
'weight' => 10, 'weight' => 10,
'url' => $entity->toUrl()->setOption('query', $this->getRedirectDestination()->getAsArray()), 'url' => $edit_url,
], ],
'disable' => [ 'disable' => [
'title' => 'Disable', 'title' => 'Disable',
...@@ -79,7 +85,7 @@ public function testList() { ...@@ -79,7 +85,7 @@ public function testList() {
'width' => 880, 'width' => 880,
]), ]),
], ],
'url' => $entity->toUrl('delete-form')->setOption('query', $this->getRedirectDestination()->getAsArray()), 'url' => $delete_url,
], ],
]; ];
...@@ -140,11 +146,50 @@ public function testList() { ...@@ -140,11 +146,50 @@ public function testList() {
$entity = $list['default']; $entity = $list['default'];
// Test getOperations() method. // Test getOperations() method.
$edit_url = $entity->toUrl()->setOption('query', $this->getRedirectDestination()->getAsArray());
$edit_url->setOption('attributes', ['aria-label' => 'Edit ' . $entity->label()]);
$delete_url = $entity->toUrl('delete-form')->setOption('query', $this->getRedirectDestination()->getAsArray());
$delete_url->setOption('attributes', ['aria-label' => 'Delete ' . $entity->label()]);
$expected_operations = [
'edit' => [
'title' => 'Edit',
'weight' => 10,
'url' => $edit_url,
],
'delete' => [
'title' => 'Delete',
'weight' => 100,
'attributes' => [
'class' => ['use-ajax'],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 880,
]),
],
'url' => $delete_url,
],
];
$actual_operations = $controller->getOperations($entity);
// Sort the operations to normalize link order.
uasort($actual_operations, ['Drupal\Component\Utility\SortArray', 'sortByWeightElement']);
$this->assertEquals($expected_operations, $actual_operations, 'The operations are identical.');
// Test getOperations when label doesn't exist.
$entity->set('label', '');
$entity->save();
$edit_url = $entity->toUrl()->setOption('query', $this->getRedirectDestination()->getAsArray());
$edit_url->setOption('attributes', ['aria-label' => 'Edit ' . $entity->bundle() . ' ' . $entity->id()]);
$delete_url = $entity->toUrl('delete-form')->setOption('query', $this->getRedirectDestination()->getAsArray());
$delete_url->setOption('attributes', ['aria-label' => 'Delete ' . $entity->bundle() . ' ' . $entity->id()]);
$expected_operations = [ $expected_operations = [
'edit' => [ 'edit' => [
'title' => 'Edit', 'title' => 'Edit',
'weight' => 10, 'weight' => 10,
'url' => $entity->toUrl()->setOption('query', $this->getRedirectDestination()->getAsArray()), 'url' => $edit_url,
], ],
'delete' => [ 'delete' => [
'title' => 'Delete', 'title' => 'Delete',
...@@ -156,7 +201,7 @@ public function testList() { ...@@ -156,7 +201,7 @@ public function testList() {
'width' => 880, 'width' => 880,
]), ]),
], ],
'url' => $entity->toUrl('delete-form')->setOption('query', $this->getRedirectDestination()->getAsArray()), 'url' => $delete_url,
], ],
]; ];
......
...@@ -75,7 +75,10 @@ public function testUserAdmin() { ...@@ -75,7 +75,10 @@ public function testUserAdmin() {
$this->assertSession()->pageTextContains($admin_user->getAccountName()); $this->assertSession()->pageTextContains($admin_user->getAccountName());
// Test for existence of edit link in table. // Test for existence of edit link in table.
$link = $user_a->toLink('Edit', 'edit-form', ['query' => ['destination' => $user_a->toUrl('collection')->toString()]])->toString(); $link = $user_a->toLink('Edit', 'edit-form', [
'query' => ['destination' => $user_a->toUrl('collection')->toString()],
'attributes' => ['aria-label' => 'Edit ' . $user_a->label()],
])->toString();
$this->assertSession()->responseContains($link); $this->assertSession()->responseContains($link);
// Test exposed filter elements. // Test exposed filter elements.
......
...@@ -184,8 +184,8 @@ protected function doTestRenderedOutput(AccountInterface $account, $check_cache ...@@ -184,8 +184,8 @@ protected function doTestRenderedOutput(AccountInterface $account, $check_cache
$output = $view->style_plugin->getField($index, 'delete_node'); $output = $view->style_plugin->getField($index, 'delete_node');
$this->assertSame($expected, (string) $output); $this->assertSame($expected, (string) $output);
$expected = $access ? ' <div class="dropbutton-wrapper" data-drupal-ajax-container><div class="dropbutton-widget"><ul class="dropbutton">' . $expected = $access ? ' <div class="dropbutton-wrapper" data-drupal-ajax-container><div class="dropbutton-widget"><ul class="dropbutton">' .
'<li><a href="' . $node_url . '/edit?destination=/" hreflang="en">Edit</a></li>' . '<li><a href="' . $node_url . '/edit?destination=/" aria-label="Edit ' . $node->label() . '" hreflang="en">Edit</a></li>' .
'<li><a href="' . $node_url . '/delete?destination=/" class="use-ajax" data-dialog-type="modal" data-dialog-options="' . Html::escape(Json::encode(['width' => 880])) . '" hreflang="en">Delete</a></li>' . '<li><a href="' . $node_url . '/delete?destination=/" aria-label="Delete ' . $node->label() . '" class="use-ajax" data-dialog-type="modal" data-dialog-options="' . Html::escape(Json::encode(['width' => 880])) . '" hreflang="en">Delete</a></li>' .
'</ul></div></div>' : ''; '</ul></div></div>' : '';
$output = $view->style_plugin->getField($index, 'operations'); $output = $view->style_plugin->getField($index, 'operations');
$this->assertSame($expected, (string) $output); $this->assertSame($expected, (string) $output);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment