Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/content_moderation/src/StateTransitionValidation.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\content_moderation; | |
4 | |
5 use Drupal\Core\Entity\ContentEntityInterface; | |
6 use Drupal\Core\Session\AccountInterface; | |
7 use Drupal\workflows\Transition; | |
8 | |
9 /** | |
10 * Validates whether a certain state transition is allowed. | |
11 */ | |
12 class StateTransitionValidation implements StateTransitionValidationInterface { | |
13 | |
14 /** | |
15 * The moderation information service. | |
16 * | |
17 * @var \Drupal\content_moderation\ModerationInformationInterface | |
18 */ | |
19 protected $moderationInfo; | |
20 | |
21 /** | |
22 * Stores the possible state transitions. | |
23 * | |
24 * @var array | |
25 */ | |
26 protected $possibleTransitions = []; | |
27 | |
28 /** | |
29 * Constructs a new StateTransitionValidation. | |
30 * | |
31 * @param \Drupal\content_moderation\ModerationInformationInterface $moderation_info | |
32 * The moderation information service. | |
33 */ | |
34 public function __construct(ModerationInformationInterface $moderation_info) { | |
35 $this->moderationInfo = $moderation_info; | |
36 } | |
37 | |
38 /** | |
39 * {@inheritdoc} | |
40 */ | |
41 public function getValidTransitions(ContentEntityInterface $entity, AccountInterface $user) { | |
42 $workflow = $this->moderationInfo->getWorkflowForEntity($entity); | |
43 $current_state = $entity->moderation_state->value ? $workflow->getTypePlugin()->getState($entity->moderation_state->value) : $workflow->getTypePlugin()->getInitialState($entity); | |
44 | |
45 return array_filter($current_state->getTransitions(), function (Transition $transition) use ($workflow, $user) { | |
46 return $user->hasPermission('use ' . $workflow->id() . ' transition ' . $transition->id()); | |
47 }); | |
48 } | |
49 | |
50 } |