3 namespace Drupal\workflows;
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;
13 * Provides a access checker for deleting a workflow state.
16 * Marked as internal until it's validated this should form part of the public
17 * API in https://www.drupal.org/node/2897148.
19 class WorkflowDeleteAccessCheck implements AccessInterface {
22 * Checks access to deleting a workflow state for a particular route.
24 * The value of '_workflow_state_delete_access' is ignored. The route must
25 * have the parameters 'workflow' and 'workflow_state'. For example:
27 * pattern: '/foo/{workflow}/bar/{workflow_state}/delete'
29 * _workflow_state_delete_access: 'true'
31 * @see \Drupal\Core\ParamConverter\EntityConverter
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.
40 * @return \Drupal\Core\Access\AccessResultInterface
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);
52 // No opinion, so other access checks should decide if access should be
54 return AccessResult::neutral();