You are here

class FacebookEmbedCodeConstraintValidator in Media entity facebook 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Validation/Constraint/FacebookEmbedCodeConstraintValidator.php \Drupal\media_entity_facebook\Plugin\Validation\Constraint\FacebookEmbedCodeConstraintValidator
  2. 3.x src/Plugin/Validation/Constraint/FacebookEmbedCodeConstraintValidator.php \Drupal\media_entity_facebook\Plugin\Validation\Constraint\FacebookEmbedCodeConstraintValidator

Validates the FacebookEmbedCode constraint.

Hierarchy

Expanded class hierarchy of FacebookEmbedCodeConstraintValidator

File

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

Namespace

Drupal\media_entity_facebook\Plugin\Validation\Constraint
View source
class FacebookEmbedCodeConstraintValidator extends ConstraintValidator {

  /**
   * {@inheritdoc}
   */
  public function validate($value, Constraint $constraint) {
    if (is_string($value)) {
      $data = $value;
    }
    elseif ($value instanceof FieldItemInterface) {
      $class = get_class($value);
      $property = $class::mainPropertyName();
      if ($property) {
        $data = $value->{$property};
      }
    }
    else {
      $data = '';
    }
    if ($data) {
      $post_url = Facebook::parseFacebookEmbedField($value);
      if ($post_url === FALSE) {
        $this->context
          ->addViolation($constraint->message);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FacebookEmbedCodeConstraintValidator::validate public function Checks if the passed value is valid.