VideoJsPlayerListFormatter.php in Video.js (HTML5 Video Player) 8
File
src/Plugin/Field/FieldFormatter/VideoJsPlayerListFormatter.php
View source
<?php
namespace Drupal\videojs\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Link;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Cache\Cache;
use Drupal\videojs\Plugin\Field\FieldFormatter\VideoJsPlayerFormatter;
class VideoJsPlayerListFormatter extends VideoJsPlayerFormatter implements ContainerFactoryPluginInterface {
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
$files = $this
->getEntitiesToView($items, $langcode);
if (empty($files)) {
return $elements;
}
$video_items = array();
foreach ($files as $delta => $file) {
$video_uri = $file
->getFileUri();
$video_items[] = Url::fromUri(file_create_url($video_uri));
}
$elements[] = array(
'#theme' => 'videojs',
'#items' => $video_items,
'#player_attributes' => $this
->getSettings(),
'#attached' => array(
'library' => array(
'videojs/videojs',
),
),
);
return $elements;
}
public static function isApplicable(FieldDefinitionInterface $field_definition) {
$entity_form_display = entity_get_form_display($field_definition
->getTargetEntityTypeId(), $field_definition
->getTargetBundle(), 'default');
$widget = $entity_form_display
->getRenderer($field_definition
->getName());
$widget_id = $widget
->getBaseId();
if ($field_definition
->isList()) {
return TRUE;
}
return FALSE;
}
}