You are here

public function FacebookEmbedCodeConstraintValidator::validate in Media entity facebook 3.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Validation/Constraint/FacebookEmbedCodeConstraintValidator.php \Drupal\media_entity_facebook\Plugin\Validation\Constraint\FacebookEmbedCodeConstraintValidator::validate()
  2. 8 src/Plugin/Validation/Constraint/FacebookEmbedCodeConstraintValidator.php \Drupal\media_entity_facebook\Plugin\Validation\Constraint\FacebookEmbedCodeConstraintValidator::validate()

File

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

Class

FacebookEmbedCodeConstraintValidator
Validates the FacebookEmbedCode constraint.

Namespace

Drupal\media_entity_facebook\Plugin\Validation\Constraint

Code

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