UnPublishStateConstraintValidator.php in Scheduler content moderation integration 8
File
src/Plugin/Validation/Constraint/UnPublishStateConstraintValidator.php
View source
<?php
namespace Drupal\scheduler_content_moderation_integration\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
class UnPublishStateConstraintValidator extends ConstraintValidatorBase {
public function validate($value, Constraint $constraint) {
$entity = $value
->getEntity();
if (!$this->moderationInformation
->isModeratedEntity($entity)) {
return;
}
if ($value
->isEmpty()) {
return;
}
if (!isset($entity->unpublish_on->value)) {
return;
}
$publish_state = $entity->publish_state->value === '_none' ? NULL : $entity->publish_state->value;
$unpublish_state = $entity->unpublish_state->value;
$moderation_state = $entity->moderation_state->value;
if ($publish_state && !$this
->isValidTransition($entity, $publish_state, $unpublish_state)) {
$this->context
->buildViolation($constraint->invalidPublishToUnPublishTransitionMessage, [
'%publish_state' => $publish_state,
'%unpublish_state' => $unpublish_state,
])
->atPath('publish_state')
->addViolation();
}
if (!$publish_state && !$this
->isValidTransition($entity, $moderation_state, $unpublish_state)) {
$this->context
->buildViolation($constraint->invalidUnPublishTransitionMessage, [
'%unpublish_state' => $unpublish_state,
'%content_state' => $moderation_state,
])
->atPath('publish_state')
->addViolation();
}
}
}