You are here

class DeletedWorkspaceConstraintValidator in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/Plugin/Validation/Constraint/DeletedWorkspaceConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\DeletedWorkspaceConstraintValidator
  2. 9 core/modules/workspaces/src/Plugin/Validation/Constraint/DeletedWorkspaceConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\DeletedWorkspaceConstraintValidator

Checks if data still exists for a deleted workspace ID.

Hierarchy

Expanded class hierarchy of DeletedWorkspaceConstraintValidator

File

core/modules/workspaces/src/Plugin/Validation/Constraint/DeletedWorkspaceConstraintValidator.php, line 14

Namespace

Drupal\workspaces\Plugin\Validation\Constraint
View source
class DeletedWorkspaceConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {

  /**
   * The workspace association service.
   *
   * @var \Drupal\workspaces\WorkspaceAssociationInterface
   */
  protected $workspaceAssociation;

  /**
   * Creates a new DeletedWorkspaceConstraintValidator instance.
   *
   * @param \Drupal\workspaces\WorkspaceAssociationInterface $workspace_association
   *   The workspace association service.
   */
  public function __construct(WorkspaceAssociationInterface $workspace_association) {
    $this->workspaceAssociation = $workspace_association;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('workspaces.association'));
  }

  /**
   * {@inheritdoc}
   */
  public function validate($value, Constraint $constraint) {

    /** @var \Drupal\Core\Field\FieldItemListInterface $value */

    // This constraint applies only to newly created workspace entities.
    if (!isset($value) || !$value
      ->getEntity()
      ->isNew()) {
      return;
    }
    if ($this->workspaceAssociation
      ->getTrackedEntities($value
      ->getEntity()
      ->id())) {
      $this->context
        ->addViolation($constraint->message);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeletedWorkspaceConstraintValidator::$workspaceAssociation protected property The workspace association service.
DeletedWorkspaceConstraintValidator::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
DeletedWorkspaceConstraintValidator::validate public function
DeletedWorkspaceConstraintValidator::__construct public function Creates a new DeletedWorkspaceConstraintValidator instance.