You are here

class SchedulerPublishOnConstraintValidator in Scheduler 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Validation/Constraint/SchedulerPublishOnConstraintValidator.php \Drupal\scheduler\Plugin\Validation\Constraint\SchedulerPublishOnConstraintValidator

Validates the SchedulerPublishOn constraint.

Hierarchy

Expanded class hierarchy of SchedulerPublishOnConstraintValidator

File

src/Plugin/Validation/Constraint/SchedulerPublishOnConstraintValidator.php, line 11

Namespace

Drupal\scheduler\Plugin\Validation\Constraint
View source
class SchedulerPublishOnConstraintValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  public function validate($entity, Constraint $constraint) {
    $publish_on = $entity->value;
    $default_publish_past_date = \Drupal::config('scheduler.settings')
      ->get('default_publish_past_date');
    $scheduler_publish_past_date = $entity
      ->getEntity()->type->entity
      ->getThirdPartySetting('scheduler', 'publish_past_date', $default_publish_past_date);
    if ($publish_on && $scheduler_publish_past_date == 'error' && $publish_on < \Drupal::time()
      ->getRequestTime()) {
      $this->context
        ->buildViolation($constraint->messagePublishOnDateNotInFuture)
        ->atPath('publish_on')
        ->addViolation();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SchedulerPublishOnConstraintValidator::validate public function Checks if the passed value is valid.