Skip to content

Commit

Permalink
Detect access before showing manage links.
Browse files Browse the repository at this point in the history
  • Loading branch information
rosiel committed Nov 7, 2022
1 parent 7eebb65 commit 386ba0c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
16 changes: 11 additions & 5 deletions src/Controller/ManageMediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\RouteMatch;
use Drupal\node\Entity\Node;
use Drupal\Core\Url;
use Drupal\node\NodeInterface;

/**
Expand Down Expand Up @@ -34,13 +35,18 @@ public function addToNodePage(NodeInterface $node) {
['query' => ["edit[$field][widget][0][target_id]" => $node->id()]]
);

$manage_link = Url::fromRoute('entity.media_type.collection')->toRenderArray();
$manage_link['#title'] = $this->t('Manage media types');
$manage_link['#type'] = 'link';
$manage_link['#prefix'] = ' ';
$manage_link['#suffix'] = '.';

return [
'#type' => 'markup',
'#markup' => $this->t("The following media types can be added because they have the <code>@field</code> field. <a href=@manage_media_page>Manage media types</a>.",
[
'@field' => $field,
'@manage_media_page' => '/admin/structure/media',
]),
'#markup' => $this->t("The following media types can be added because they have the <code>@field</code> field.", [
'@field' => $field,
]),
'manage_link' => $manage_link,
'add_media' => $add_media_list,
];
}
Expand Down
16 changes: 11 additions & 5 deletions src/Controller/ManageMembersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Entity\Controller\EntityController;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\islandora\IslandoraUtils;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -98,13 +99,18 @@ public function addToNodePage(NodeInterface $node) {
['query' => ["edit[$field][widget][0][target_id]" => $node->id()]]
);

$manage_link = Url::fromRoute('entity.node_type.collection')->toRenderArray();
$manage_link['#title'] = $this->t('Manage content types');
$manage_link['#type'] = 'link';
$manage_link['#prefix'] = ' ';
$manage_link['#suffix'] = '.';

return [
'#type' => 'markup',
'#markup' => $this->t("The following content types can be added because they have the <code>@field</code> field. <a href=@manage_content_types>Manage content types</a>.",
[
'@field' => $field,
'@manage_content_types' => '/admin/structure/types',
]),
'#markup' => $this->t("The following content types can be added because they have the <code>@field</code> field.", [
'@field' => $field,
]),
'manage_link' => $manage_link,
'add_node' => $add_node_list,
];
}
Expand Down

0 comments on commit 386ba0c

Please sign in to comment.