You are here

class BrightcoveVideo in Brightcove Video Connect 8.2

Same name in this branch
  1. 8.2 src/Entity/BrightcoveVideo.php \Drupal\brightcove\Entity\BrightcoveVideo
  2. 8.2 modules/media_brightcove/src/Plugin/media/Source/BrightcoveVideo.php \Drupal\media_brightcove\Plugin\media\Source\BrightcoveVideo
  3. 8.2 modules/media_entity_brightcove/src/Plugin/MediaEntity/Type/BrightcoveVideo.php \Drupal\media_entity_brightcove\Plugin\MediaEntity\Type\BrightcoveVideo
Same name and namespace in other branches
  1. 8 modules/media_entity_brightcove/src/Plugin/MediaEntity/Type/BrightcoveVideo.php \Drupal\media_entity_brightcove\Plugin\MediaEntity\Type\BrightcoveVideo
  2. 3.x modules/media_entity_brightcove/src/Plugin/MediaEntity/Type/BrightcoveVideo.php \Drupal\media_entity_brightcove\Plugin\MediaEntity\Type\BrightcoveVideo

Defines video field type for media.

Plugin annotation


@MediaType(
  id = "media_entity_brightcove",
  label = @Translation("Brightcove Video"),
  description = @Translation("Provides business logic and metadata for videos.")
)

Hierarchy

Expanded class hierarchy of BrightcoveVideo

File

modules/media_entity_brightcove/src/Plugin/MediaEntity/Type/BrightcoveVideo.php, line 19

Namespace

Drupal\media_entity_brightcove\Plugin\MediaEntity\Type
View source
class BrightcoveVideo extends MediaTypeBase {

  /**
   * The used field name.
   */
  const FIELD_NAME = 'field_video';

  /**
   * {@inheritdoc}
   */
  public function providedFields() {
    return [
      'name' => $this
        ->t('Name'),
      'complete' => $this
        ->t('Complete'),
      'description' => $this
        ->t('Description'),
      'long_description' => $this
        ->t('Long description'),
      'reference_id' => $this
        ->t('Reference ID'),
      'state' => $this
        ->t('State'),
      'tags' => $this
        ->t('Tags'),
      'custom_fields' => $this
        ->t('Custom fields'),
      'geo' => $this
        ->t('Geo information'),
      'geo.countries' => $this
        ->t('Geo countries'),
      'geo.exclude_countries' => $this
        ->t('Exclude countries'),
      'geo.restricted' => $this
        ->t('Geo Restricted'),
      'schedule' => $this
        ->t('Schedule'),
      'starts_at' => $this
        ->t('Starts at'),
      'ends_at' => $this
        ->t('Ends at'),
      'picture_thumbnail' => $this
        ->t('Thumbnail picture'),
      'picture_poster' => $this
        ->t('Picture poster'),
      'video_source' => $this
        ->t('Video source'),
      'economics' => $this
        ->t('Economics'),
      'partner_channel' => $this
        ->t('Partner channel'),
    ];
  }

  /**
   * Returns the data stored on this video media as object.
   *
   * @return \Brightcove\Item\Video\Video|null
   *   Brightcove video entity or null if not exist.
   *
   * @todo Decide whether we want to have our own custom domain value object.
   */
  public function getVideo(MediaInterface $media) {

    /** @var \Drupal\brightcove\Entity\BrightcoveVideo $video */
    if ($video = $media->{static::FIELD_NAME}->entity) {
      $cms = BrightcoveUtil::getCmsApi($video
        ->getApiClient());
      $brightcove_video = $cms
        ->getVideo($video
        ->getBrightcoveId());
      return $brightcove_video;
    }
    return NULL;
  }

  /**
   * Returns the brightcove video entity.
   *
   * @param \Drupal\media_entity\MediaInterface $media
   *   The media.
   *
   * @return \Drupal\brightcove\Entity\BrightcoveVideo
   *   Brightcove video entity.
   */
  public function getVideoEntity(MediaInterface $media) {
    return $media->{static::FIELD_NAME}->entity;
  }

  /**
   * {@inheritdoc}
   */
  public function getField(MediaInterface $media, $name) {
    switch ($name) {
      case 'thumbnail':
        return $this
          ->thumbnail($media);
      case 'name':
        return $this
          ->getVideoEntity($media)
          ->getName();
      case 'complete':
        break;
      case 'description':
        return $this
          ->getVideoEntity($media)
          ->getDescription();
      case 'long_description':
        return $this
          ->getVideoEntity($media)
          ->getLongDescription();
      case 'reference_id':
        return $this
          ->getVideoEntity($media)
          ->getReferenceId();
      case 'state':
        break;
      case 'tags':
        return $this
          ->getVideoEntity($media)
          ->getTags();
      case 'custom_fields':
        return $this
          ->getVideoEntity($media)
          ->getCustomFieldValues();
      case 'geo':
        break;
      case 'geo.countries':
        return $this
          ->getVideoEntity($media)->geo_countries->value;
      case 'geo.exclude_countries':
        return $this
          ->getVideoEntity($media)->geo_exclude_countries->value;
      case 'geo.restricted':
        return $this
          ->getVideoEntity($media)->geo_restricted->value;
      case 'schedule':
        break;
      case 'starts_at':
        return $this
          ->getVideoEntity($media)
          ->getScheduleStartsAt();
      case 'ends_at':
        return $this
          ->getVideoEntity($media)
          ->getScheduleEndsAt();
      case 'picture_thumbnail':
        return $this
          ->thumbnail($media);
      case 'picture_poster':
        return $this
          ->getVideoEntity($media)
          ->getPoster();
      case 'video_source':
        return $this
          ->getVideoEntity($media)
          ->getVideoUrl();
      case 'economics':
        return $this
          ->getVideoEntity($media)
          ->getEconomics();
      case 'partner_channel':
        break;
    }
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function thumbnail(MediaInterface $media) {
    if ($thumbnail_info = $this
      ->getVideoEntity($media)
      ->getThumbnail()) {

      /** @var \Drupal\file\FileInterface $file */
      if ($file = $this->entityTypeManager
        ->getStorage('file')
        ->load($thumbnail_info['target_id'])) {
        return $file
          ->getFileUri();
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getDefaultName(MediaInterface $media) {
    return $this
      ->getField($media, 'name');
  }

  /**
   * {@inheritdoc}
   */
  protected function getSourceFieldName() {

    // Must be implemented to return something that fits into the 32 characters
    // limit for a field name.
    // @TODO: Check if this needs to be unique.
    // @see \Drupal\media_entity\MediaTypeBase::getSourceFieldName()
    return 'brightcove_video';
  }

  /**
   * {@inheritdoc}
   */
  public function createSourceFieldStorage() {
    return $this->entityTypeManager
      ->getStorage('field_storage_config')
      ->create([
      'entity_type' => 'media',
      'field_name' => $this
        ->getSourceFieldName(),
      'type' => 'entity_reference',
      'settings' => [
        'target_type' => 'brightcove_video',
      ],
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function createSourceField(MediaBundleInterface $bundle) {
    return $this->entityTypeManager
      ->getStorage('field_config')
      ->create([
      'field_storage' => $this
        ->getSourceFieldStorage(),
      'bundle' => $bundle
        ->id(),
      'required' => TRUE,
      'label' => 'Brightcove Video',
      'settings' => [
        'handler' => 'default:brightcove_video',
      ],
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BrightcoveVideo::createSourceField public function
BrightcoveVideo::createSourceFieldStorage public function
BrightcoveVideo::FIELD_NAME constant The used field name.
BrightcoveVideo::getDefaultName public function Provide a default name for the media. Overrides MediaTypeBase::getDefaultName
BrightcoveVideo::getField public function Gets a media-related field/value. Overrides MediaTypeInterface::getField
BrightcoveVideo::getSourceFieldName protected function
BrightcoveVideo::getVideo public function Returns the data stored on this video media as object.
BrightcoveVideo::getVideoEntity public function Returns the brightcove video entity.
BrightcoveVideo::providedFields public function Gets list of fields provided by this plugin. Overrides MediaTypeInterface::providedFields
BrightcoveVideo::thumbnail public function Gets thumbnail image. Overrides MediaTypeInterface::thumbnail
MediaTypeBase::$config protected property Media entity image config object.
MediaTypeBase::$entityFieldManager protected property The entity field manager service.
MediaTypeBase::$entityTypeManager protected property The entity type manager service.
MediaTypeBase::$label protected property Plugin label.
MediaTypeBase::attachConstraints public function Attaches type-specific constraints to media. Overrides MediaTypeInterface::attachConstraints
MediaTypeBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm 1
MediaTypeBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
MediaTypeBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
MediaTypeBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurablePluginInterface::defaultConfiguration 1
MediaTypeBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurablePluginInterface::getConfiguration
MediaTypeBase::getDefaultThumbnail public function Gets the default thumbnail image. Overrides MediaTypeInterface::getDefaultThumbnail
MediaTypeBase::label public function Returns the display label. Overrides MediaTypeInterface::label
MediaTypeBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurablePluginInterface::setConfiguration
MediaTypeBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
MediaTypeBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
MediaTypeBase::__construct public function Constructs a new class instance. Overrides PluginBase::__construct
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.
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.