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); } } }