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.
15 class WorkflowDeleteAccessCheck implements AccessInterface {
18 * Checks access to deleting a workflow state for a particular route.
20 * The value of '_workflow_state_delete_access' is ignored. The route must
21 * have the parameters 'workflow' and 'workflow_state'. For example:
23 * pattern: '/foo/{workflow}/bar/{workflow_state}/delete'
25 * _workflow_state_delete_access: 'true'
27 * @see \Drupal\Core\ParamConverter\EntityConverter
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.
36 * @return \Drupal\Core\Access\AccessResultInterface
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);
48 // No opinion, so other access checks should decide if access should be
50 return AccessResult::neutral();