annotate core/modules/workflows/src/WorkflowDeleteAccessCheck.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children 12f9dff5fda9
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\workflows;
Chris@0 4
Chris@0 5 use Drupal\Core\Access\AccessResult;
Chris@0 6 use Drupal\Core\Entity\EntityInterface;
Chris@0 7 use Drupal\Core\Routing\Access\AccessInterface;
Chris@0 8 use Drupal\Core\Routing\RouteMatchInterface;
Chris@0 9 use Drupal\Core\Session\AccountInterface;
Chris@0 10 use Symfony\Component\Routing\Route;
Chris@0 11
Chris@0 12 /**
Chris@0 13 * Provides a access checker for deleting a workflow state.
Chris@0 14 *
Chris@0 15 * @internal
Chris@0 16 * Marked as internal until it's validated this should form part of the public
Chris@0 17 * API in https://www.drupal.org/node/2897148.
Chris@0 18 */
Chris@0 19 class WorkflowDeleteAccessCheck implements AccessInterface {
Chris@0 20
Chris@0 21 /**
Chris@0 22 * Checks access to deleting a workflow state for a particular route.
Chris@0 23 *
Chris@0 24 * The value of '_workflow_state_delete_access' is ignored. The route must
Chris@0 25 * have the parameters 'workflow' and 'workflow_state'. For example:
Chris@0 26 * @code
Chris@0 27 * pattern: '/foo/{workflow}/bar/{workflow_state}/delete'
Chris@0 28 * requirements:
Chris@0 29 * _workflow_state_delete_access: 'true'
Chris@0 30 * @endcode
Chris@0 31 * @see \Drupal\Core\ParamConverter\EntityConverter
Chris@0 32 *
Chris@0 33 * @param \Symfony\Component\Routing\Route $route
Chris@0 34 * The route to check against.
Chris@0 35 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
Chris@0 36 * The parametrized route
Chris@0 37 * @param \Drupal\Core\Session\AccountInterface $account
Chris@0 38 * The currently logged in account.
Chris@0 39 *
Chris@0 40 * @return \Drupal\Core\Access\AccessResultInterface
Chris@0 41 * The access result.
Chris@0 42 */
Chris@0 43 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
Chris@0 44 // If there is valid entity of the given entity type, check its access.
Chris@0 45 $parameters = $route_match->getParameters();
Chris@0 46 if ($parameters->has('workflow') && $parameters->has('workflow_state')) {
Chris@0 47 $entity = $parameters->get('workflow');
Chris@0 48 if ($entity instanceof EntityInterface) {
Chris@0 49 return $entity->access('delete-state:' . $parameters->get('workflow_state'), $account, TRUE);
Chris@0 50 }
Chris@0 51 }
Chris@0 52 // No opinion, so other access checks should decide if access should be
Chris@0 53 // allowed or not.
Chris@0 54 return AccessResult::neutral();
Chris@0 55 }
Chris@0 56
Chris@0 57 }