VideoUrlFormatter.php in Video 8.2
Same filename and directory in other branches
Contains \Drupal\video\Plugin\Field\FieldFormatter\VidePlayerFormatter.
Namespace
Drupal\video\Plugin\Field\FieldFormatterFile
src/Plugin/Field/FieldFormatter/VideoUrlFormatter.phpView source
<?php
/**
* @file
* Contains \Drupal\video\Plugin\Field\FieldFormatter\VidePlayerFormatter.
*/
namespace Drupal\video\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;
/**
* Plugin implementation of the 'video_player' formatter.
*
* @FieldFormatter(
* id = "video_url",
* label = @Translation("Url to Video "),
* field_types = {
* "video"
* }
* )
*/
class VideoUrlFormatter extends VideoPlayerFormatterBase implements ContainerFactoryPluginInterface {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructs an VideoPlayerFormatter object.
*
* @param string $plugin_id
* The plugin_id for the formatter.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The definition of the field to which the formatter is associated.
* @param array $settings
* The formatter settings.
* @param string $label
* The formatter label display setting.
* @param string $view_mode
* The view mode.
* @param array $third_party_settings
* Any third party settings settings.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], $container
->get('current_user'));
}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = array();
$files = $this
->getEntitiesToView($items, $langcode);
// Early opt-out if the field is empty.
if (empty($files)) {
return $elements;
}
// Collect cache tags to be added for each item in the field.
foreach ($files as $delta => $file) {
$video_uri = file_create_url($file
->getFileUri());
$elements[$delta] = [
'#markup' => $video_uri,
];
}
return $elements;
}
}
Classes
Name | Description |
---|---|
VideoUrlFormatter | Plugin implementation of the 'video_player' formatter. |