class EntityLabelNotNullConstraintValidator in Automatic Entity Label 8.3
Same name and namespace in other branches
- 8 src/Plugin/Validation/EntityLabelNotNullConstraintValidator.php \Drupal\auto_entitylabel\Plugin\Validation\EntityLabelNotNullConstraintValidator
- 8.2 src/Plugin/Validation/EntityLabelNotNullConstraintValidator.php \Drupal\auto_entitylabel\Plugin\Validation\EntityLabelNotNullConstraintValidator
EntityLabelNotNull constraint validator.
Custom override of NotNull constraint to allow empty entity labels to validate before the automatic label is set.
Hierarchy
- class \Drupal\Core\Validation\Plugin\Validation\Constraint\NotNullConstraintValidator extends \Symfony\Component\Validator\Constraints\NotNullValidator uses TypedDataAwareValidatorTrait
- class \Drupal\auto_entitylabel\Plugin\Validation\EntityLabelNotNullConstraintValidator implements ContainerInjectionInterface
Expanded class hierarchy of EntityLabelNotNullConstraintValidator
File
- src/
Plugin/ Validation/ EntityLabelNotNullConstraintValidator.php, line 18
Namespace
Drupal\auto_entitylabel\Plugin\ValidationView source
class EntityLabelNotNullConstraintValidator extends NotNullConstraintValidator implements ContainerInjectionInterface {
/**
* The entity decorator service.
*
* @var \Drupal\auto_entitylabel\EntityDecorator
*/
protected $entityDecorator;
/**
* Creates an EntityLabelNotNullConstraintValidator object.
*
* @param \Drupal\auto_entitylabel\EntityDecorator $entityDecorator
* The entity decorator service.
*/
public function __construct(EntityDecorator $entityDecorator) {
$this->entityDecorator = $entityDecorator;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('auto_entitylabel.entity_decorator'));
}
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint) {
$typed_data = $this
->getTypedData();
if ($typed_data instanceof FieldItemList && $typed_data
->isEmpty()) {
$entity = $typed_data
->getEntity();
/** @var \Drupal\auto_entitylabel\AutoEntityLabelManager $decorated_entity */
$decorated_entity = $this->entityDecorator
->decorate($entity);
if ($decorated_entity
->hasLabel() && $decorated_entity
->autoLabelNeeded()) {
return;
}
}
parent::validate($value, $constraint);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityLabelNotNullConstraintValidator:: |
protected | property | The entity decorator service. | |
EntityLabelNotNullConstraintValidator:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
EntityLabelNotNullConstraintValidator:: |
public | function |
Checks if the passed value is valid. Overrides NotNullConstraintValidator:: |
|
EntityLabelNotNullConstraintValidator:: |
public | function | Creates an EntityLabelNotNullConstraintValidator object. | |
TypedDataAwareValidatorTrait:: |
public | function | Gets the typed data object for the validated value. |