You are here

class TweetEmbedCodeConstraintValidator in Media entity Twitter 8

Validates the TweetEmbedCode constraint.

Hierarchy

Expanded class hierarchy of TweetEmbedCodeConstraintValidator

1 file declares its use of TweetEmbedCodeConstraintValidator
ConstraintsTest.php in tests/src/Unit/ConstraintsTest.php

File

src/Plugin/Validation/Constraint/TweetEmbedCodeConstraintValidator.php, line 13

Namespace

Drupal\media_entity_twitter\Plugin\Validation\Constraint
View source
class TweetEmbedCodeConstraintValidator extends ConstraintValidator {
  use EmbedCodeValueTrait;

  /**
   * {@inheritdoc}
   */
  public function validate($value, Constraint $constraint) {
    $value = $this
      ->getEmbedCode($value);
    if (!isset($value)) {
      return;
    }
    foreach (Twitter::$validationRegexp as $pattern => $key) {
      if (preg_match($pattern, $value)) {
        return;
      }
    }
    $this->context
      ->addViolation($constraint->message);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EmbedCodeValueTrait::getEmbedCode protected function Extracts the raw embed code from input which may or may not be wrapped.
TweetEmbedCodeConstraintValidator::validate public function Checks if the passed value is valid.