You are here

protected function PinEmbedCodeConstraintValidator::getEmbedCode in Media entity Pinterest 8.2

Extracts the raw embed code from input which may or may not be wrapped.

Parameters

mixed $value: The input value. Can be a normal string or a value wrapped by the Typed Data API.

Return value

string|null The raw embed code.

1 call to PinEmbedCodeConstraintValidator::getEmbedCode()
PinEmbedCodeConstraintValidator::validate in src/Plugin/Validation/Constraint/PinEmbedCodeConstraintValidator.php
Checks if the passed value is valid.

File

src/Plugin/Validation/Constraint/PinEmbedCodeConstraintValidator.php, line 47

Class

PinEmbedCodeConstraintValidator
Validates the PinEmbedCode constraint.

Namespace

Drupal\media_entity_pinterest\Plugin\Validation\Constraint

Code

protected function getEmbedCode($value) {
  if (is_string($value)) {
    return $value;
  }
  elseif ($value instanceof FieldItemInterface) {
    $class = get_class($value);
    $property = $class::mainPropertyName();
    if ($property) {
      return $value->{$property};
    }
  }
}