Version 1
[yaffs-website] / web / core / modules / workflows / src / WorkflowDeleteAccessCheck.php
1 <?php
2
3 namespace Drupal\workflows;
4
5 use Drupal\Core\Access\AccessResult;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Routing\Access\AccessInterface;
8 use Drupal\Core\Routing\RouteMatchInterface;
9 use Drupal\Core\Session\AccountInterface;
10 use Symfony\Component\Routing\Route;
11
12 /**
13  * Provides a access checker for deleting a workflow state.
14  */
15 class WorkflowDeleteAccessCheck implements AccessInterface {
16
17   /**
18    * Checks access to deleting a workflow state for a particular route.
19    *
20    * The value of '_workflow_state_delete_access' is ignored. The route must
21    * have the parameters 'workflow' and 'workflow_state'. For example:
22    * @code
23    * pattern: '/foo/{workflow}/bar/{workflow_state}/delete'
24    * requirements:
25    *   _workflow_state_delete_access: 'true'
26    * @endcode
27    * @see \Drupal\Core\ParamConverter\EntityConverter
28    *
29    * @param \Symfony\Component\Routing\Route $route
30    *   The route to check against.
31    * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
32    *   The parametrized route
33    * @param \Drupal\Core\Session\AccountInterface $account
34    *   The currently logged in account.
35    *
36    * @return \Drupal\Core\Access\AccessResultInterface
37    *   The access result.
38    */
39   public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
40     // If there is valid entity of the given entity type, check its access.
41     $parameters = $route_match->getParameters();
42     if ($parameters->has('workflow') && $parameters->has('workflow_state')) {
43       $entity = $parameters->get('workflow');
44       if ($entity instanceof EntityInterface) {
45         return $entity->access('delete-state:' . $parameters->get('workflow_state'), $account, TRUE);
46       }
47     }
48     // No opinion, so other access checks should decide if access should be
49     // allowed or not.
50     return AccessResult::neutral();
51   }
52
53 }