You are here

class Vimeo in Video Embed Field 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/video_embed_field/Provider/Vimeo.php \Drupal\video_embed_field\Plugin\video_embed_field\Provider\Vimeo

A Vimeo provider plugin.

Plugin annotation


@VideoEmbedProvider(
  id = "vimeo",
  title = @Translation("Vimeo")
)

Hierarchy

Expanded class hierarchy of Vimeo

1 file declares its use of Vimeo
ProviderUrlParseTest.php in tests/src/Unit/ProviderUrlParseTest.php

File

src/Plugin/video_embed_field/Provider/Vimeo.php, line 15

Namespace

Drupal\video_embed_field\Plugin\video_embed_field\Provider
View source
class Vimeo extends ProviderPluginBase {

  /**
   * {@inheritdoc}
   */
  public function renderEmbedCode($width, $height, $autoplay) {
    $iframe = [
      '#type' => 'video_embed_iframe',
      '#provider' => 'vimeo',
      '#url' => sprintf('https://player.vimeo.com/video/%s', $this
        ->getVideoId()),
      '#query' => [
        'autoplay' => $autoplay,
      ],
      '#attributes' => [
        'width' => $width,
        'height' => $height,
        'frameborder' => '0',
        'allowfullscreen' => 'allowfullscreen',
      ],
    ];
    if ($time_index = $this
      ->getTimeIndex()) {
      $iframe['#fragment'] = sprintf('t=%s', $time_index);
    }
    return $iframe;
  }

  /**
   * {@inheritdoc}
   */
  public function getRemoteThumbnailUrl() {
    return $this
      ->oEmbedData()->thumbnail_url;
  }

  /**
   * Get the vimeo oembed data.
   *
   * @return array
   *   An array of data from the oembed endpoint.
   */
  protected function oEmbedData() {
    return json_decode(file_get_contents('http://vimeo.com/api/oembed.json?url=' . $this
      ->getInput()));
  }

  /**
   * {@inheritdoc}
   */
  public static function getIdFromInput($input) {
    preg_match('/^https?:\\/\\/(www\\.)?vimeo.com\\/(channels\\/[a-zA-Z0-9]*\\/)?(?<id>[0-9]*)(\\/[a-zA-Z0-9]+)?(\\#t=(\\d+)s)?$/', $input, $matches);
    return isset($matches['id']) ? $matches['id'] : FALSE;
  }

  /**
   * Get the time index from the URL.
   *
   * @return string|FALSE
   *   A time index parameter to pass to the frame or FALSE if none is found.
   */
  protected function getTimeIndex() {
    preg_match('/\\#t=(?<time_index>(\\d+)s)$/', $this->input, $matches);
    return isset($matches['time_index']) ? $matches['time_index'] : FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getName() {
    return $this
      ->oEmbedData()->title;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
ProviderPluginBase::$fileSystem protected property
ProviderPluginBase::$httpClient protected property An http client.
ProviderPluginBase::$input protected property The input that caused the embed provider to be selected.
ProviderPluginBase::$thumbsDirectory protected property The directory where thumbnails are stored.
ProviderPluginBase::$videoId protected property The ID of the video.
ProviderPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
ProviderPluginBase::downloadThumbnail public function Download the remote thumbnail URL to the local thumbnail URI. Overrides ProviderPluginInterface::downloadThumbnail
ProviderPluginBase::getFileSystem protected function Get the file system service.
ProviderPluginBase::getInput protected function Get the input which caused this plugin to be selected.
ProviderPluginBase::getLocalThumbnailUri public function Get the URL to the local thumbnail. Overrides ProviderPluginInterface::getLocalThumbnailUri
ProviderPluginBase::getVideoId protected function Get the ID of the video.
ProviderPluginBase::isApplicable public static function Check if the plugin is applicable to the user input. Overrides ProviderPluginInterface::isApplicable
ProviderPluginBase::renderThumbnail public function Render a thumbnail. Overrides ProviderPluginInterface::renderThumbnail
ProviderPluginBase::__construct public function Create a plugin with the given input. Overrides PluginBase::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
Vimeo::getIdFromInput public static function Get the ID of the video from user input. Overrides ProviderPluginInterface::getIdFromInput
Vimeo::getName public function Get the name of the video. Overrides ProviderPluginBase::getName
Vimeo::getRemoteThumbnailUrl public function Get the URL of the remote thumbnail. Overrides ProviderPluginInterface::getRemoteThumbnailUrl
Vimeo::getTimeIndex protected function Get the time index from the URL.
Vimeo::oEmbedData protected function Get the vimeo oembed data.
Vimeo::renderEmbedCode public function Render embed code. Overrides ProviderPluginInterface::renderEmbedCode