You are here

public function DeletedWorkspaceConstraintValidator::validate in Workspace 8.2

File

src/Plugin/Validation/Constraint/DeletedWorkspaceConstraintValidator.php, line 45

Class

DeletedWorkspaceConstraintValidator
Checks if data still exists for a deleted workspace ID.

Namespace

Drupal\workspace\Plugin\Validation\Constraint

Code

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;
  }
  $count = $this->workspaceAssociationStorage
    ->getQuery()
    ->allRevisions()
    ->accessCheck(FALSE)
    ->condition('workspace', $value
    ->getEntity()
    ->id())
    ->count()
    ->execute();
  if ($count) {
    $this->context
      ->addViolation($constraint->message);
  }
}