You are here

FacebookEmbedCodeConstraintValidator.php in Media entity facebook 8

File

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

namespace Drupal\media_entity_facebook\Plugin\Validation\Constraint;

use Drupal\media_entity\EmbedCodeValueTrait;
use Drupal\media_entity_facebook\Plugin\MediaEntity\Type\Facebook;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

/**
 * Validates the FacebookEmbedCode constraint.
 */
class FacebookEmbedCodeConstraintValidator extends ConstraintValidator {
  use EmbedCodeValueTrait;

  /**
   * {@inheritdoc}
   */
  public function validate($value, Constraint $constraint) {
    $value = $this
      ->getEmbedCode($value);
    if (!isset($value)) {
      return;
    }
    $post_url = Facebook::parseFacebookEmbedField($value);
    if ($post_url === FALSE) {
      $this->context
        ->addViolation($constraint->message);
    }
  }

}

Classes

Namesort descending Description
FacebookEmbedCodeConstraintValidator Validates the FacebookEmbedCode constraint.