Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / media_entity / src / EmbedCodeValueTrait.php
1 <?php
2
3 namespace Drupal\media_entity;
4
5 use Drupal\Core\Field\FieldItemInterface;
6
7 /**
8  * A trait to assist with handling external embed codes.
9  */
10 trait EmbedCodeValueTrait {
11
12   /**
13    * Extracts the raw embed code from input which may or may not be wrapped.
14    *
15    * @param mixed $value
16    *   The input value. Can be a normal string or a value wrapped by the
17    *   Typed Data API.
18    *
19    * @return string|null
20    *   The raw embed code.
21    */
22   protected function getEmbedCode($value) {
23     if (is_string($value)) {
24       return $value;
25     }
26     elseif ($value instanceof FieldItemInterface) {
27       $class = get_class($value);
28       $property = $class::mainPropertyName();
29       if ($property) {
30         return $value->$property;
31       }
32     }
33   }
34
35 }