NotNullConstraint example

/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $value->getEntity();

    // Ignore entities that are not subject to moderation anyway.     if (!$this->moderationInformation->isModeratedEntity($entity)) {
      return;
    }

    // If the entity is moderated and the item list is empty, ensure users see     // the same required message as typical NotNull constraints.     if ($value->isEmpty()) {
      $this->context->addViolation((new NotNullConstraint())->message);
      return;
    }

    $workflow = $this->moderationInformation->getWorkflowForEntity($entity);

    if (!$workflow->getTypePlugin()->hasState($entity->moderation_state->value)) {
      // If the state we are transitioning to doesn't exist, we can't validate       // the transitions for this entity further.       $this->context->addViolation($constraint->invalidStateMessage, [
        '%state' => $entity->moderation_state->value,
        '%workflow' => $workflow->label(),
      ]);
Home | Imprint | This part of the site doesn't use cookies.