Security update for Core, with self-updated composer
[yaffs-website] / web / modules / contrib / videojs / src / Plugin / Field / FieldFormatter / VideoJsPlayerListFormatter.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\videojs\Plugin\Field\FieldFormatter\VideoJsPlayerListFormatter.
6  */
7
8 namespace Drupal\videojs\Plugin\Field\FieldFormatter;
9
10 use Drupal\Core\Field\FieldItemListInterface;
11 use Drupal\Core\Field\FieldDefinitionInterface;
12 use Drupal\Core\Link;
13 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
14 use Drupal\Core\Session\AccountInterface;
15 use Drupal\Core\Url;
16 use Symfony\Component\DependencyInjection\ContainerInterface;
17 use Drupal\Core\Form\FormStateInterface;
18 use Drupal\Core\Cache\Cache;
19 use Drupal\videojs\Plugin\Field\FieldFormatter\VideoJsPlayerFormatter;
20
21 /**
22  * Plugin implementation of the 'videojs_player_list' formatter.
23  *
24  * @FieldFormatter(
25  *   id = "videojs_player_list",
26  *   label = @Translation("Video.js Player"),
27  *   field_types = {
28  *     "file",
29  *     "video"
30  *   }
31  * )
32  */
33
34 class VideoJsPlayerListFormatter extends VideoJsPlayerFormatter implements ContainerFactoryPluginInterface {
35
36   /**
37    * {@inheritdoc}
38    */
39   public function viewElements(FieldItemListInterface $items, $langcode) {
40     $elements = array();
41     $files = $this->getEntitiesToView($items, $langcode);
42
43     // Early opt-out if the field is empty.
44     if (empty($files)) {
45       return $elements;
46     }
47
48     // Collect cache tags to be added for each item in the field.
49     $video_items = array();
50     foreach ($files as $delta => $file) {
51       $video_uri = $file->getFileUri();
52       $video_items[] = Url::fromUri(file_create_url($video_uri));
53     }
54     $elements[] = array(
55       '#theme' => 'videojs',
56       '#items' => $video_items,
57       '#player_attributes' => $this->getSettings(),
58       '#attached' => array(
59         'library' => array('videojs/videojs'),
60       ),
61     );
62     return $elements;
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public static function isApplicable(FieldDefinitionInterface $field_definition) {
69     return $field_definition->isList();
70   }
71 }