You are here

class CommerceSkuNotNullConstraintValidator in Commerce AutoSKU 8.2

EntityLabelNotNull constraint validator.

Custom override of NotNull constraint to allow empty entity labels to validate before the automatic label is set.

Hierarchy

Expanded class hierarchy of CommerceSkuNotNullConstraintValidator

File

src/Plugin/Validation/CommerceSkuNotNullConstraintValidator.php, line 15

Namespace

Drupal\commerce_autosku\Plugin\Validation
View source
class CommerceSkuNotNullConstraintValidator extends NotNullConstraintValidator {

  /**
   * {@inheritdoc}
   */
  public function validate($value, Constraint $constraint) {
    $typed_data = $this
      ->getTypedData();
    if ($typed_data instanceof FieldItemList && $typed_data
      ->isEmpty()) {
      $entity = $typed_data
        ->getEntity();
      if (!$entity
        ->hasField('sku')) {
        parent::validate($value, $constraint);
        return;
      }
      $decorator = \Drupal::service('commerce_autosku.entity_decorator');

      /** @var \Drupal\commerce_autosku\CommerceAutoSkuManager $decorated_entity */
      $decorated_entity = $decorator
        ->decorate($entity);
      if ($decorated_entity
        ->hasSku() && $decorated_entity
        ->autoSkuNeeded()) {
        return;
      }
    }
    parent::validate($value, $constraint);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommerceSkuNotNullConstraintValidator::validate public function Checks if the passed value is valid. Overrides NotNullConstraintValidator::validate
TypedDataAwareValidatorTrait::getTypedData public function Gets the typed data object for the validated value.