PublishStateConstraintValidator.php in Scheduler content moderation integration 8
File
src/Plugin/Validation/Constraint/PublishStateConstraintValidator.php
View source
<?php
namespace Drupal\scheduler_content_moderation_integration\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
class PublishStateConstraintValidator extends ConstraintValidatorBase {
public function validate($value, Constraint $constraint) {
$entity = $value
->getEntity();
if (!$this->moderationInformation
->isModeratedEntity($entity)) {
return;
}
if ($value
->isEmpty()) {
return;
}
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();
}
}
}