Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

Rendered Video psuedo-field #23

Open
wants to merge 2 commits into
base: 8.x-1.x
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions media_entity_embeddable_video.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* @file
* Provides functionality for embeddable videos in media entities.
*/

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\media_entity\Entity\MediaBundle;

/**
* Implements hook_entity_extra_field_info().
*/
function media_entity_embeddable_video_entity_extra_field_info() {
$fields = [];
foreach (MediaBundle::loadMultiple() as $bundle) {
if ($bundle->getType()->getPluginId() == 'embeddable_video') {
$fields['media'][$bundle->id()]['display']['rendered_video'] = [
'label' => t('Rendered Video'),
'description' => t('The rendered video for embedding.'),
'weight' => 100,
'visible' => TRUE,
];
}
}

return $fields;
}

/**
* Implements hook_entity_extra_field_info().
*/
function media_entity_embeddable_video_media_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
//if ($entity)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be remove I guess?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, removed in added commit.

if ($display->getComponent('rendered_video')) {
$build['rendered_video'] = $entity->getType()->matchProvider($entity)->render();
}
}