abstract class ConstraintValidatorBase in Scheduler content moderation integration 8
Base class for Scheduler Content Moderation Integration validators.
@package Drupal\scheduler_content_moderation_integration\Plugin\Validation\Constraint
Hierarchy
- class \Drupal\scheduler_content_moderation_integration\Plugin\Validation\Constraint\ConstraintValidatorBase extends \Symfony\Component\Validator\ConstraintValidator implements ContainerInjectionInterface
Expanded class hierarchy of ConstraintValidatorBase
File
- src/
Plugin/ Validation/ Constraint/ ConstraintValidatorBase.php, line 17
Namespace
Drupal\scheduler_content_moderation_integration\Plugin\Validation\ConstraintView source
abstract class ConstraintValidatorBase extends ConstraintValidator implements ContainerInjectionInterface {
/**
* The content moderation information service.
*
* @var \Drupal\content_moderation\ModerationInformationInterface
*/
protected $moderationInformation;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $account;
/**
* SchedulerModerationConstraintValidator constructor.
*
* @param \Drupal\content_moderation\ModerationInformationInterface $moderationInformation
* The content moderation information service.
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
*/
public function __construct(ModerationInformationInterface $moderationInformation, AccountInterface $account) {
$this->moderationInformation = $moderationInformation;
$this->account = $account;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('content_moderation.moderation_information'), $container
->get('current_user'));
}
/**
* Gets the workflow type from the supplied entity's configured workflow.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The content entity to get the workflow type for.
*
* @return \Drupal\workflows\WorkflowTypeInterface
* The workflow type.
*/
protected function getEntityWorkflowType(ContentEntityInterface $entity) {
return $this->moderationInformation
->getWorkflowForEntity($entity)
->getTypePlugin();
}
/**
* Validate transition.
*
* Validate that the transition between the supplied states is a valid
* transition for the supplied entity.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity containing the workflow to check against.
* @param string $from_state
* The state to transition from.
* @param string $to_state
* The state to transition to.
*
* @return bool
* TRUE if it's a valid transition. FALSE, otherwise.
*/
protected function isValidTransition(ContentEntityInterface $entity, $from_state, $to_state) {
$workflow_type = $this
->getEntityWorkflowType($entity);
if (!$workflow_type
->hasState($from_state) || !$workflow_type
->hasState($to_state)) {
return FALSE;
}
$from = $workflow_type
->getState($from_state);
return $from
->canTransitionTo($to_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConstraintValidatorBase:: |
protected | property | The current user. | |
ConstraintValidatorBase:: |
protected | property | The content moderation information service. | |
ConstraintValidatorBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
ConstraintValidatorBase:: |
protected | function | Gets the workflow type from the supplied entity's configured workflow. | |
ConstraintValidatorBase:: |
protected | function | Validate transition. | |
ConstraintValidatorBase:: |
public | function | SchedulerModerationConstraintValidator constructor. |