function EntityReferenceSupportedNewEntitiesConstraintValidator::validate
Same name in other branches
- 8.9.x core/modules/workspaces/src/Plugin/Validation/Constraint/EntityReferenceSupportedNewEntitiesConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\EntityReferenceSupportedNewEntitiesConstraintValidator::validate()
- 10 core/modules/workspaces/src/Plugin/Validation/Constraint/EntityReferenceSupportedNewEntitiesConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\EntityReferenceSupportedNewEntitiesConstraintValidator::validate()
- 11.x core/modules/workspaces/src/Plugin/Validation/Constraint/EntityReferenceSupportedNewEntitiesConstraintValidator.php \Drupal\workspaces\Plugin\Validation\Constraint\EntityReferenceSupportedNewEntitiesConstraintValidator::validate()
File
-
core/
modules/ workspaces/ src/ Plugin/ Validation/ Constraint/ EntityReferenceSupportedNewEntitiesConstraintValidator.php, line 52
Class
- EntityReferenceSupportedNewEntitiesConstraintValidator
- Checks if new entities created for entity reference fields are supported.
Namespace
Drupal\workspaces\Plugin\Validation\ConstraintCode
public function validate($value, Constraint $constraint) {
// The validator should run only if we are in a active workspace context.
if (!$this->workspaceManager
->hasActiveWorkspace()) {
return;
}
$target_entity_type_id = $value->getFieldDefinition()
->getFieldStorageDefinition()
->getSetting('target_type');
$target_entity_type = $this->entityTypeManager
->getDefinition($target_entity_type_id);
if ($value->hasNewEntity() && !$this->workspaceManager
->isEntityTypeSupported($target_entity_type)) {
$this->context
->addViolation($constraint->message, [
'%collection_label' => $target_entity_type->getCollectionLabel(),
]);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.