comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
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 * @internal
16 * Marked as internal until it's validated this should form part of the public
17 * API in https://www.drupal.org/node/2897148.
18 */
19 class WorkflowDeleteAccessCheck implements AccessInterface {
20
21 /**
22 * Checks access to deleting a workflow state for a particular route.
23 *
24 * The value of '_workflow_state_delete_access' is ignored. The route must
25 * have the parameters 'workflow' and 'workflow_state'. For example:
26 * @code
27 * pattern: '/foo/{workflow}/bar/{workflow_state}/delete'
28 * requirements:
29 * _workflow_state_delete_access: 'true'
30 * @endcode
31 * @see \Drupal\Core\ParamConverter\EntityConverter
32 *
33 * @param \Symfony\Component\Routing\Route $route
34 * The route to check against.
35 * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
36 * The parametrized route
37 * @param \Drupal\Core\Session\AccountInterface $account
38 * The currently logged in account.
39 *
40 * @return \Drupal\Core\Access\AccessResultInterface
41 * The access result.
42 */
43 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
44 // If there is valid entity of the given entity type, check its access.
45 $parameters = $route_match->getParameters();
46 if ($parameters->has('workflow') && $parameters->has('workflow_state')) {
47 $entity = $parameters->get('workflow');
48 if ($entity instanceof EntityInterface) {
49 return $entity->access('delete-state:' . $parameters->get('workflow_state'), $account, TRUE);
50 }
51 }
52 // No opinion, so other access checks should decide if access should be
53 // allowed or not.
54 return AccessResult::neutral();
55 }
56
57 }