class EntityWorkspaceConflictConstraintValidator
Same name in other branches
- 9 core/modules/workspaces/src/Plugin/Validation/Constraint/EntityWorkspaceConflictConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\EntityWorkspaceConflictConstraintValidator
- 8.9.x core/modules/workspaces/src/Plugin/Validation/Constraint/EntityWorkspaceConflictConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\EntityWorkspaceConflictConstraintValidator
- 10 core/modules/workspaces/src/Plugin/Validation/Constraint/EntityWorkspaceConflictConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\EntityWorkspaceConflictConstraintValidator
Validates the EntityWorkspaceConflict constraint.
@internal
Hierarchy
- class \Drupal\workspaces\Plugin\Validation\Constraint\EntityWorkspaceConflictConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface
Expanded class hierarchy of EntityWorkspaceConflictConstraintValidator
File
-
core/
modules/ workspaces/ src/ Plugin/ Validation/ Constraint/ EntityWorkspaceConflictConstraintValidator.php, line 18
Namespace
Drupal\workspaces\Plugin\Validation\ConstraintView source
class EntityWorkspaceConflictConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
public function __construct(EntityTypeManagerInterface $entityTypeManager, WorkspaceManagerInterface $workspaceManager, WorkspaceAssociationInterface $workspaceAssociation) {
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('entity_type.manager'), $container->get('workspaces.manager'), $container->get('workspaces.association'));
}
/**
* {@inheritdoc}
*/
public function validate($entity, Constraint $constraint) : void {
/** @var \Drupal\Core\Entity\EntityInterface $entity */
if (isset($entity) && !$entity->isNew()) {
$active_workspace = $this->workspaceManager
->getActiveWorkspace();
// If the entity is tracked in a workspace, it can only be edited in
// that workspace or one of its descendants.
if ($tracking_workspace_ids = $this->workspaceAssociation
->getEntityTrackingWorkspaceIds($entity, TRUE)) {
if (!$active_workspace || !in_array($active_workspace->id(), $tracking_workspace_ids, TRUE)) {
$first_tracking_workspace_id = reset($tracking_workspace_ids);
$workspace = $this->entityTypeManager
->getStorage('workspace')
->load($first_tracking_workspace_id);
$this->context
->buildViolation($constraint->message)
->setParameter('@label', $workspace->label())
->addViolation();
}
}
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
EntityWorkspaceConflictConstraintValidator::create | public static | function | Instantiates a new instance of this class. | Overrides ContainerInjectionInterface::create |
EntityWorkspaceConflictConstraintValidator::validate | public | function | ||
EntityWorkspaceConflictConstraintValidator::__construct | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.