Browse Source

Hide media and members tabs on non-Islandora objects. (#160)

* Use custom access to test type of node

* Also hide Members tab

* Separate permission for node fields

* Check for correct field

* Add phpdoc and make both fields required.

* Remove whitespace
pull/729/head
Jared Whiklo 5 years ago committed by Mark Jordan
parent
commit
c3fa84500e
  1. 28
      src/Controller/ManageMediaController.php
  2. 4
      src/EventSubscriber/AdminViewsRouteSubscriber.php

28
src/Controller/ManageMediaController.php

@ -2,6 +2,9 @@
namespace Drupal\islandora\Controller; namespace Drupal\islandora\Controller;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\RouteMatch;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
/** /**
@ -14,6 +17,9 @@ class ManageMediaController extends ManageMembersController {
* *
* @param \Drupal\node\NodeInterface $node * @param \Drupal\node\NodeInterface $node
* Node you want to add a media to. * Node you want to add a media to.
*
* @return array
* Array of media types to add.
*/ */
public function addToNodePage(NodeInterface $node) { public function addToNodePage(NodeInterface $node) {
return $this->generateTypeList( return $this->generateTypeList(
@ -26,4 +32,26 @@ class ManageMediaController extends ManageMembersController {
); );
} }
/**
* Check if the object being displayed "is Islandora".
*
* @param \Drupal\Core\Routing\RouteMatch $route_match
* The current routing match.
*
* @return \Drupal\Core\Access\AccessResultAllowed|\Drupal\Core\Access\AccessResultForbidden
* Whether we can or can't show the "thing".
*/
public function access(RouteMatch $route_match) {
if ($route_match->getParameters()->has('node')) {
$node = $route_match->getParameter('node');
if (!$node instanceof NodeInterface) {
$node = Node::load($node);
}
if ($node->hasField('field_model') && $node->hasField('field_member_of')) {
return AccessResult::allowed();
}
}
return AccessResult::forbidden();
}
} }

4
src/EventSubscriber/AdminViewsRouteSubscriber.php

@ -16,9 +16,13 @@ class AdminViewsRouteSubscriber extends RouteSubscriberBase {
protected function alterRoutes(RouteCollection $collection) { protected function alterRoutes(RouteCollection $collection) {
if ($route = $collection->get('view.media_of.page_1')) { if ($route = $collection->get('view.media_of.page_1')) {
$route->setOption('_admin_route', 'TRUE'); $route->setOption('_admin_route', 'TRUE');
$route->setRequirement('_permission', 'manage media');
$route->setRequirement('_custom_access', '\Drupal\islandora\Controller\ManageMediaController::access');
} }
if ($route = $collection->get('view.manage_members.page_1')) { if ($route = $collection->get('view.manage_members.page_1')) {
$route->setOption('_admin_route', 'TRUE'); $route->setOption('_admin_route', 'TRUE');
$route->setRequirement('_permission', 'manage members');
$route->setRequirement('_custom_access', '\Drupal\islandora\Controller\ManageMediaController::access');
} }
} }

Loading…
Cancel
Save