/** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $element = array(); foreach ($items as $delta => $item) { /** @var \Drupal\media_entity_embeddable_video\VideoProviderInterface $provider */ $provider = $this->videoProviderManager->getProviderByEmbedCode($item->value); if ($provider) { $element[$delta] = $provider->render(); } } return $element; }
/** * {@inheritdoc} */ public function matchProvider(MediaInterface $media) { $source_field = $this->configuration['source_field']; $property_name = $media->{$source_field}->first()->mainPropertyName(); return $this->videoProviders->getProviderByEmbedCode($media->{$source_field}->{$property_name}); }