Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin' into ISAICP-6346
Browse files Browse the repository at this point in the history
  • Loading branch information
saidatom committed Aug 4, 2021
2 parents 1145dc8 + c248511 commit f150e13
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 4 deletions.
4 changes: 2 additions & 2 deletions config/sync/block.block.three_dots_menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ theme: joinup_theme
region: featured
weight: -17
provider: null
plugin: local_tasks_block
plugin: joinup_local_tasks_block
settings:
id: local_tasks_block
id: joinup_local_tasks_block
label: Tabs
provider: core
label_display: '0'
Expand Down
2 changes: 1 addition & 1 deletion tests/behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ default:
Contact information inline form: '#edit-field-ar-contact-information-wrapper'
Content: '.section--content-middle'
Cookie consent banner: '#cookie-consent-banner'
Entity actions: '.block-local-tasks-block'
Entity actions: '.block-joinup-local-tasks-block'
Footer: '.section--footer'
Header menu: '#block-joinup-theme-main-menu'
Header: '.section--featured'
Expand Down
81 changes: 81 additions & 0 deletions tests/features/local_actions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
@api @group-b
Feature:
As an owner of the website
In order for users to easier navigate in the website
The local actions should be helpful in entities.

Scenario: The 'View' local action does not show in the canonical path.
Given I am logged in as a moderator

Given collection:
| title | Test collection |
| state | validated |
When I go to the "Test collection" collection
Then I should not see the link "View" in the "Entity actions" region
When I click "Metadata" in the "Entity actions" region
Then I should see the link "View" in the "Entity actions" region

Given solution:
| title | Test solution |
| collection | Test collection |
| state | validated |
When I go to the "Test solution" solution
Then I should not see the link "View" in the "Entity actions" region
When I click "Metadata" in the "Entity actions" region
Then I should see the link "View" in the "Entity actions" region

Given release:
| title | Test release |
| is version of | Test solution |
| state | validated |
When I go to the "Test release" release
Then I should not see the link "View" in the "Entity actions" region
When I click "Metadata" in the "Entity actions" region
Then I should see the link "View" in the "Entity actions" region

Given distribution:
| title | Test distribution |
| parent | Test release |
When I go to the "Test distribution" distribution
Then I should not see the link "View" in the "Entity actions" region
When I click "Metadata" in the "Entity actions" region
Then I should see the link "View" in the "Entity actions" region

Given licence:
| title | Test licence |
When I go to the "Test licence" licence
Then I should not see the link "View" in the "Entity actions" region
When I click "Metadata" in the "Entity actions" region
Then I should see the link "View" in the "Entity actions" region

Given discussion content:
| title | collection | state |
| Test discussion | Test collection | validated |
When I go to the "Test discussion" discussion
Then I should not see the link "View" in the "Entity actions" region
When I click "Delete" in the "Entity actions" region
Then I should see the link "View" in the "Entity actions" region

Given document content:
| title | collection | state |
| Test document | Test collection | validated |
When I go to the "Test document" document
Then I should not see the link "View" in the "Entity actions" region
When I click "Delete" in the "Entity actions" region
Then I should see the link "View" in the "Entity actions" region

Given event content:
| title | collection | state |
| Test event | Test collection | validated |
When I go to the "Test event" event
Then I should not see the link "View" in the "Entity actions" region
When I click "Delete" in the "Entity actions" region
Then I should see the link "View" in the "Entity actions" region

Given news content:
| title | collection | state |
| Test news | Test collection | validated |
When I go to the "Test news" news
Then I should not see the link "View" in the "Entity actions" region
When I click "Delete" in the "Entity actions" region
Then I should see the link "View" in the "Entity actions" region
1 change: 1 addition & 0 deletions tests/features/user/profile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Feature: User profile
And I should see the avatar "user_icon.png"

But I should not see the text "Country of origin:" in the "Header" region
And I should not see the link "View" in the "Entity actions" region

When I click "Edit"
Then the following fields should be present "Current password, Email, Password, Confirm password, First name"
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Traits/MaterialDesignTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected function selectMaterialDesignRadioButton(string $label, TraversableEle

// Wait until the animation completes and the radio button is selected.
$xpath = '//label[text()="' . $label . '"]/../parent::label[contains(concat(" ", normalize-space(@class), " "), " is-checked ")]/span[contains(concat(" ", normalize-space(@class), " "), " mdl-radio__ripple-container ")]';
$end = microtime(TRUE) + 5;
$end = microtime(TRUE) + 10;
do {
usleep(100000);
// The plus button opening animation runs from the top right to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,14 @@ field.formatter.settings.entity_reference_custom_link:
limit:
type: integer
label: limit

block.settings.joinup_local_tasks_block:
type: block_settings
label: 'Tabs block'
mapping:
primary:
type: boolean
label: 'Whether primary tabs are shown'
secondary:
type: boolean
label: 'Whether secondary tabs are shown'
15 changes: 15 additions & 0 deletions web/modules/custom/joinup_core/joinup_core.module
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\AccessResultInterface;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
Expand Down Expand Up @@ -378,3 +379,17 @@ function joinup_core_entity_view_alter(array &$build, EntityInterface $entity, E
->applyTo($build);
}
}

/**
* Implements hook_menu_local_tasks_alter().
*/
function joinup_core_menu_local_tasks_alter(&$data, $route_name, RefinableCacheableDependencyInterface &$cacheability) {
$routes = [
'entity.node.canonical',
'entity.rdf_entity.canonical',
'entity.user.canonical',
];
if (in_array($route_name, $routes) && isset($data['tabs'][0][$route_name])) {
$data['tabs'][0][$route_name]['#access'] = FALSE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types = 1);

namespace Drupal\joinup_core\Plugin\Block;

use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Menu\Plugin\Block\LocalTasksBlock;
use Drupal\Core\Render\Element;

/**
* Provides a "Tabs" block to display the local tasks.
*
* Drupal has a mechanism that prevents showing the primary tabs if only one
* option is allowed. This is based on the idea that the active (current) tab is
* always visible so if there is only 1 tab active, it is the current one and
* the user does not need to click to go to the current page.
*
* In Joinup, we are hiding off the "View" tab for canonical paths. This can
* result in cases where there is only 1 tab left but it is not the current one.
* Thus, we need to override the primary tabs block in order to allow a single
* tab to be viewed.
*
* @Block(
* id = "joinup_local_tasks_block",
* admin_label = @Translation("Tabs"),
* )
*/
class JoinupLocalTasksBlock extends LocalTasksBlock {

/**
* {@inheritdoc}
*/
public function build(): array {
$config = $this->configuration;
$cacheability = new CacheableMetadata();
$cacheability->addCacheableDependency($this->localTaskManager);
$tabs = [
'#theme' => 'menu_local_tasks',
];

// Add only selected levels for the printed output.
if ($config['primary']) {
$links = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName(), 0);
$cacheability = $cacheability->merge($links['cacheability']);

// Do not display single tabs if the only tab points to the same page.
$visible_children = Element::getVisibleChildren($links['tabs']);
$cacheability = $cacheability->merge($links['cacheability']);
$count = count($visible_children);
$tabs += [
'#primary' => ($count === 0 || ($count === 1 && key($visible_children) === $this->routeMatch->getRouteName())) ? [] : $links['tabs'],
];
}
if ($config['secondary']) {
$links = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName(), 1);
// Do not display single tabs if the only tab points to the same page.
$visible_children = Element::getVisibleChildren($links['tabs']);
$cacheability = $cacheability->merge($links['cacheability']);
$count = count($visible_children);
// Do not display single tabs if the only tab points to the same page.
$tabs += [
'#secondary' => ($count === 0 || ($count === 1 && key($visible_children) === $this->routeMatch->getRouteName())) ? [] : $links['tabs'],
];
}

$build = [];
$cacheability->applyTo($build);
if (empty($tabs['#primary']) && empty($tabs['#secondary'])) {
return $build;
}

return $build + $tabs;
}

}

0 comments on commit f150e13

Please sign in to comment.