class DeletedWorkspaceConstraintValidator in Workspace 8.2
Checks if data still exists for a deleted workspace ID.
Hierarchy
- class \Drupal\workspace\Plugin\Validation\Constraint\DeletedWorkspaceConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator implements ContainerInjectionInterface
Expanded class hierarchy of DeletedWorkspaceConstraintValidator
File
- src/
Plugin/ Validation/ Constraint/ DeletedWorkspaceConstraintValidator.php, line 14
Namespace
Drupal\workspace\Plugin\Validation\ConstraintView source
class DeletedWorkspaceConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
/**
* The workspace association storage.
*
* @var \Drupal\workspace\WorkspaceAssociationStorageInterface
*/
protected $workspaceAssociationStorage;
/**
* Creates a new DeletedWorkspaceConstraintValidator instance.
*
* @param \Drupal\workspace\WorkspaceAssociationStorageInterface $workspace_association_storage
* The workspace association storage.
*/
public function __construct(WorkspaceAssociationStorageInterface $workspace_association_storage) {
$this->workspaceAssociationStorage = $workspace_association_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager')
->getStorage('workspace_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;
}
$count = $this->workspaceAssociationStorage
->getQuery()
->allRevisions()
->accessCheck(FALSE)
->condition('workspace', $value
->getEntity()
->id())
->count()
->execute();
if ($count) {
$this->context
->addViolation($constraint->message);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeletedWorkspaceConstraintValidator:: |
protected | property | The workspace association storage. | |
DeletedWorkspaceConstraintValidator:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
DeletedWorkspaceConstraintValidator:: |
public | function | Checks if the passed value is valid. | |
DeletedWorkspaceConstraintValidator:: |
public | function | Creates a new DeletedWorkspaceConstraintValidator instance. |