You are here

GalleryMediaBundleConstraintValidator.php in D7 Media 8

File

src/Plugin/Validation/Constraint/GalleryMediaBundleConstraintValidator.php
View source
<?php

namespace Drupal\media\Plugin\Validation\Constraint;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

/**
 * Validates the GalleryMediaBundle constraint.
 */
class GalleryMediaBundleConstraintValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  public function validate($value, Constraint $constraint) {
    if (!isset($value)) {
      return;
    }
    if ($value
      ->hasField($constraint->sourceFieldName)) {
      $slideshowItems = $value
        ->get($constraint->sourceFieldName);
      foreach ($slideshowItems as $item) {
        if ($item->entity
          ->getType()
          ->getPluginId() == "slideshow") {
          $this->context
            ->addViolation($constraint->message);
        }
      }
    }
  }

}

Classes

Namesort descending Description
GalleryMediaBundleConstraintValidator Validates the GalleryMediaBundle constraint.