comparison core/modules/workflows/src/WorkflowDeleteAccessCheck.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
1 <?php 1 <?php
2 2
3 namespace Drupal\workflows; 3 namespace Drupal\workflows;
4 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; 5 use Drupal\Core\Routing\RouteMatchInterface;
9 use Drupal\Core\Session\AccountInterface; 6 use Drupal\Core\Session\AccountInterface;
10 use Symfony\Component\Routing\Route;
11 7
12 /** 8 /**
13 * Provides a access checker for deleting a workflow state. 9 * Provides a access checker for deleting a workflow state.
14 * 10 *
15 * @internal 11 * @internal
16 * Marked as internal until it's validated this should form part of the public 12 * Marked as internal for use by the workflows module only.
17 * API in https://www.drupal.org/node/2897148. 13 *
14 * @deprecated
15 * Using the _workflow_state_delete_access check is deprecated in Drupal 8.6.0
16 * and will be removed before Drupal 9.0.0, you can use _workflow_access in
17 * route definitions instead.
18 * @code
19 * # The old approach:
20 * requirements:
21 * _workflow_state_delete_access: 'true'
22 * # The new approach:
23 * requirements:
24 * _workflow_access: 'delete-state'
25 * @endcode
26 * As an internal API the ability to use _workflow_state_delete_access may
27 * also be removed in a minor release.
28 *
29 * @see \Drupal\workflows\WorkflowStateTransitionOperationsAccessCheck
30 * @see https://www.drupal.org/node/2929327
18 */ 31 */
19 class WorkflowDeleteAccessCheck implements AccessInterface { 32 class WorkflowDeleteAccessCheck extends WorkflowStateTransitionOperationsAccessCheck {
20 33
21 /** 34 /**
22 * Checks access to deleting a workflow state for a particular route. 35 * {@inheritdoc}
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 */ 36 */
43 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) { 37 public function access(RouteMatchInterface $route_match, AccountInterface $account) {
44 // If there is valid entity of the given entity type, check its access. 38 @trigger_error('Using the _workflow_state_delete_access check is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0, use _workflow_access instead. As an internal API _workflow_state_delete_access may also be removed in a minor release.', E_USER_DEPRECATED);
45 $parameters = $route_match->getParameters(); 39 return parent::access($route_match, $account);
46 if ($parameters->has('workflow') && $parameters->has('workflow_state')) { 40 }
47 $entity = $parameters->get('workflow'); 41
48 if ($entity instanceof EntityInterface) { 42 /**
49 return $entity->access('delete-state:' . $parameters->get('workflow_state'), $account, TRUE); 43 * {@inheritdoc}
50 } 44 */
51 } 45 protected function getOperation(RouteMatchInterface $route_match) {
52 // No opinion, so other access checks should decide if access should be 46 return 'delete-state';
53 // allowed or not.
54 return AccessResult::neutral();
55 } 47 }
56 48
57 } 49 }