Commit d16a6cdc authored by Igor Biki's avatar Igor Biki
Browse files

ISTWCMS-3908 Replacing permission check with path validator.

parent a8778d12
......@@ -70,11 +70,13 @@ class AllowedBlocks extends LayoutBuilderRestrictionBase {
* {@inheritDoc}
*/
public function alterBlockDefinitions(array $definitions, array $context) {
// Respect restrictions on allowed blocks specified by the section storage.
// Load configuration for allowed blocks.
$allowed_blocks = $this->configFactory->get('uw_dashboard.allowed_blocks')
->get('allowed_blocks');
$allowed_block_definitions = [];
// Filter blocks only for dashboard override, while for admin dashboard
// layout page will display all available blocks.
if ($allowed_blocks && isset($context['section_storage']) && $context['section_storage']->getPluginId() === 'dashboards_override') {
foreach ($allowed_blocks as $key => $allowed_block) {
if (isset($definitions[$key])) {
......
......@@ -60,11 +60,12 @@ function uw_dashboard_toolbar_alter(&$items) {
// Adding config form for user with permission to update it. This prevents
// menu item to be displayed and getting access denied by clicking on it.
if (\Drupal::currentUser()->hasPermission('administer dashboards')) {
$url = Url::fromRoute('uw_dashboard.allowed_blocks');
if (\Drupal::service('path.validator')->isValid($url->getInternalPath())) {
$items['dashboards']['tray']['dashboards']['#items'][] = [
'#type' => 'link',
'#title' => 'Allowed blocks',
'#url' => Url::fromRoute('uw_dashboard.allowed_blocks'),
'#url' => $url,
];
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment