This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin' into ISAICP-6346
- Loading branch information
Showing
8 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
web/modules/custom/joinup_core/src/Plugin/Block/JoinupLocalTasksBlock.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |