You are here

trait EmbedCodeValueTrait in Media entity 8

A trait to assist with handling external embed codes.

Hierarchy

File

src/EmbedCodeValueTrait.php, line 10

Namespace

Drupal\media_entity
View source
trait EmbedCodeValueTrait {

  /**
   * Extracts the raw embed code from input which may or may not be wrapped.
   *
   * @param mixed $value
   *   The input value. Can be a normal string or a value wrapped by the
   *   Typed Data API.
   *
   * @return string|null
   *   The raw embed 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};
      }
    }
  }

}

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.