You are here

public function EntityLabelNotNullConstraintValidator::validate in Automatic Entity Label 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/Validation/EntityLabelNotNullConstraintValidator.php \Drupal\auto_entitylabel\Plugin\Validation\EntityLabelNotNullConstraintValidator::validate()
  2. 8.2 src/Plugin/Validation/EntityLabelNotNullConstraintValidator.php \Drupal\auto_entitylabel\Plugin\Validation\EntityLabelNotNullConstraintValidator::validate()

Overrides NotNullConstraintValidator::validate

File

src/Plugin/Validation/EntityLabelNotNullConstraintValidator.php, line 20

Class

EntityLabelNotNullConstraintValidator
EntityLabelNotNull constraint validator.

Namespace

Drupal\auto_entitylabel\Plugin\Validation

Code

public function validate($value, Constraint $constraint) {
  $typed_data = $this
    ->getTypedData();
  if ($typed_data instanceof FieldItemList && $typed_data
    ->isEmpty()) {
    $entity = $typed_data
      ->getEntity();
    $decorator = \Drupal::service('auto_entitylabel.entity_decorator');

    /** @var \Drupal\auto_entitylabel\AutoEntityLabelManager $decorated_entity */
    $decorated_entity = $decorator
      ->decorate($entity);
    if ($decorated_entity
      ->hasLabel() && $decorated_entity
      ->autoLabelNeeded()) {
      return;
    }
  }
  parent::validate($value, $constraint);
}