class PublishStateConstraintValidator in Scheduler content moderation integration 8
Validator for the PublishStateConstraint.
Hierarchy
- class \Drupal\scheduler_content_moderation_integration\Plugin\Validation\Constraint\ConstraintValidatorBase extends \Symfony\Component\Validator\ConstraintValidator implements ContainerInjectionInterface
- class \Drupal\scheduler_content_moderation_integration\Plugin\Validation\Constraint\PublishStateConstraintValidator
Expanded class hierarchy of PublishStateConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ PublishStateConstraintValidator.php, line 10
Namespace
Drupal\scheduler_content_moderation_integration\Plugin\Validation\ConstraintView source
class PublishStateConstraintValidator extends ConstraintValidatorBase {
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $value
->getEntity();
// No need to validate entities that are not moderated.
if (!$this->moderationInformation
->isModeratedEntity($entity)) {
return;
}
// No need to validate if a moderation state has not ben set.
if ($value
->isEmpty()) {
return;
}
// No need to validate when there is no time set.
if (!isset($entity->publish_on->value)) {
return;
}
$moderation_state = $entity->moderation_state->value;
$publish_state = $entity->publish_state->value;
if (!$this
->isValidTransition($entity, $moderation_state, $publish_state)) {
$this->context
->buildViolation($constraint->invalidTransitionMessage, [
'%publish_state' => $publish_state,
'%content_state' => $moderation_state,
])
->atPath('publish_state')
->addViolation();
}
}
}
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. | |
PublishStateConstraintValidator:: |
public | function | Checks if the passed value is valid. |