Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supported drupal 9 #2

Open
wants to merge 1 commit into
base: 8.x-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 1 addition & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,11 @@
"description": "Video module allows you to embedded videos from YouTube, Vimeo, Facebook, Vine etc (Drupal 8 only) and upload videos and play using HTML5 video player.",
"type": "drupal-module",
"homepage": "https://www.drupal.org/project/video",
"keywords": ["Drupal", "media", "video", "transcode", "embed"],
"license": "GPL-2.0+",
"authors": [
{
"name": "Heshan Wanigasooriya",
"homepage": "https://www.drupal.org/u/heshanlk",
"role": "Maintainer"
}
],
"minimum-stability": "8.x-2.x",
"extra": {
"drupal": {
"package": "Field types",
"version": "8.x-2.x"
}
},
"support": {
"issues": "https://www.drupal.org/project/issues/video",
"source": "https://www.drupal.org/project/video"
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
"version": "8.x-1.x"
}
],
"require": {
"drupal/core": "~8.1",
}
}
18 changes: 9 additions & 9 deletions modules/video_transcode/src/Form/PresetFormBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Drupal\video_transcode\Form;

use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -24,9 +24,9 @@
class PresetFormBase extends EntityForm {

/**
* @var \Drupal\Core\Entity\Query\QueryFactory
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $entityQueryFactory;
protected $entityTypeManager;

/**
* Construct the PresetFormBase.
Expand All @@ -36,11 +36,11 @@ class PresetFormBase extends EntityForm {
* from the container. We later use this query factory to build an entity
* query for the exists() method.
*
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
* An entity query factory for the preset entity type.
*/
public function __construct(QueryFactory $query_factory) {
$this->entityQueryFactory = $query_factory;
public function __construct(EntityTypeManager $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}

/**
Expand All @@ -58,7 +58,7 @@ public function __construct(QueryFactory $query_factory) {
* pass the factory to our class as a constructor parameter.
*/
public static function create(ContainerInterface $container) {
return new static($container->get('entity.query'));
return new static($container->get('entity_type.manager'));
}

/**
Expand Down Expand Up @@ -521,8 +521,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
* TRUE if this format already exists, FALSE otherwise.
*/
public function exists($entity_id, array $element, FormStateInterface $form_state) {
// Use the query factory to build a new preset entity query.
$query = $this->entityQueryFactory->get('video_transcode_preset');
// Use the entity type manager to build a new preset entity query.
$query = $this->entityTypeManager->getStorage('video_transcode_preset')->getQuery();

// Query the entity ID to see if its in use.
$result = $query->condition('id', $element['#field_prefix'] . $entity_id)
Expand Down
21 changes: 5 additions & 16 deletions src/Plugin/Field/FieldFormatter/VideoEmbedPlayerFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
$file = File::load($item->target_id);
if(!$file) continue;
$metadata = isset($item->data) ? unserialize($item->data) : [];
$scheme = \Drupal::service('file_system')->uriScheme($file->getFileUri());
#$scheme = file_uri_scheme($file->getFileUri());
$scheme = \Drupal\Core\StreamWrapper\StreamWrapperManager::getScheme($file->getFileUri());
$provider = $this->providerManager->loadProviderFromStream($scheme, $file, $metadata);
if($provider){
$element[$delta] = $provider->renderEmbedCode($settings);
Expand Down Expand Up @@ -146,21 +147,9 @@ public static function isApplicable(FieldDefinitionInterface $field_definition)
if(empty($field_definition->getTargetBundle())){
return TRUE;
}
else {
$form_mode = 'default';
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load($field_definition->getTargetEntityTypeId() . '.' . $field_definition->getTargetBundle() . '.' . $form_mode);
if (!$entity_form_display) {
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->create([
'targetEntityType' => $field_definition->getTargetEntityTypeId(),
'bundle' => $field_definition->getTargetBundle(),
'mode' => $form_mode,
'status' => TRUE,
]);
}
else{
#$entity_form_display = entity_get_form_display($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
$entity_form_display= \Drupal::service('entity_display.repository')->getFormDisplay($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
$widget = $entity_form_display->getRenderer($field_definition->getName());
$widget_id = $widget->getBaseId();
if($widget_id == 'video_embed'){
Expand Down
41 changes: 9 additions & 32 deletions src/Plugin/Field/FieldFormatter/VideoEmbedThumbnailFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,20 @@ class VideoEmbedThumbnailFormatter extends FormatterBase implements ContainerFac
public function viewElements(FieldItemListInterface $items, $langcode) {
// load widget settings
$field_definition = $this->fieldDefinition;
$form_mode = 'default';
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load($field_definition->getTargetEntityTypeId() . '.' . $field_definition->getTargetBundle() . '.' . $form_mode);
if (!$entity_form_display) {
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->create([
'targetEntityType' => $field_definition->getTargetEntityTypeId(),
'bundle' => $field_definition->getTargetBundle(),
'mode' => $form_mode,
'status' => TRUE,
]);
}
#$entity_form_display = entity_get_form_display($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
$entity_form_display= \Drupal::service('entity_display.repository')->getFormDisplay($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
$widget = $entity_form_display->getRenderer($field_definition->getName());
$widget_settings = $widget->getSettings();
$element = [];
foreach ($items as $delta => $item) {
$file = File::load($item->target_id);
$metadata = isset($item->data) ? unserialize($item->data) : [];
$scheme = file_uri_scheme($file->getFileUri());
$provider = $this->providerManager->loadProviderFromStream($scheme, $file, $metadata, $widget_settings);
#$scheme = file_uri_scheme($file->getFileUri());
$scheme = \Drupal\Core\StreamWrapper\StreamWrapperManager::getScheme($file->getFileUri());
$provider = $this->providerManager->loadProviderFromStream($scheme, $file, $metadata, $widget_settings);
$url = FALSE;
if ($this->getSetting('link_image_to') == static::LINK_CONTENT) {
$url = $items->getEntity()->toUrl();
$url = $items->getEntity()->urlInfo();
}
elseif ($this->getSetting('link_image_to') == static::LINK_PROVIDER) {
$url = Url::fromUri(file_create_url($file->getFileUri()));
Expand Down Expand Up @@ -174,21 +163,9 @@ public static function isApplicable(FieldDefinitionInterface $field_definition)
return TRUE;
}
else{
$form_mode = 'default';
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load($field_definition->getTargetEntityTypeId() . '.' . $field_definition->getTargetBundle() . '.' . $form_mode);
if (!$entity_form_display) {
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->create([
'targetEntityType' => $field_definition->getTargetEntityTypeId(),
'bundle' => $field_definition->getTargetBundle(),
'mode' => $form_mode,
'status' => TRUE,
]);
}
$widget = $entity_form_display->getRenderer($field_definition->getName());
#$entity_form_display = entity_get_form_display($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
$entity_form_display= \Drupal::service('entity_display.repository')->getFormDisplay($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
$widget = $entity_form_display->getRenderer($field_definition->getName());
$widget_id = $widget->getBaseId();
if($widget_id == 'video_embed'){
return TRUE;
Expand Down
23 changes: 6 additions & 17 deletions src/Plugin/Field/FieldFormatter/VideoPlayerFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,16 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
// Collect cache tags to be added for each item in the field.
foreach ($files as $delta => $file) {
$video_uri = $file->getFileUri();
$relative_url = file_url_transform_relative(file_create_url($video_uri));
$elements[$delta] = [
'#theme' => 'video_player_formatter',
'#items' => [Url::fromUri(file_create_url($video_uri))],
'#items' => [Url::fromUserInput($relative_url)],
'#player_attributes' => $this->getSettings(),
];
}
return $elements;
}

/**
* {@inheritdoc}
*/
Expand All @@ -186,20 +187,8 @@ public static function isApplicable(FieldDefinitionInterface $field_definition)
return TRUE;
}
else{
$form_mode = 'default';
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load($field_definition->getTargetEntityTypeId() . '.' . $field_definition->getTargetBundle() . '.' . $form_mode);
if (!$entity_form_display) {
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->create([
'targetEntityType' => $field_definition->getTargetEntityTypeId(),
'bundle' => $field_definition->getTargetBundle(),
'mode' => $form_mode,
'status' => TRUE,
]);
}
#$entity_form_display = entity_get_form_display($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
$entity_form_display = \Drupal::service('entity_display.repository')->getFormDisplay($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
$widget = $entity_form_display->getRenderer($field_definition->getName());
$widget_id = $widget->getBaseId();
if($widget_id == 'video_upload'){
Expand All @@ -208,4 +197,4 @@ public static function isApplicable(FieldDefinitionInterface $field_definition)
}
return FALSE;
}
}
}
21 changes: 5 additions & 16 deletions src/Plugin/Field/FieldFormatter/VideoPlayerListFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
$video_items = [];
foreach ($files as $delta => $file) {
$video_uri = $file->getFileUri();
$video_items[] = Url::fromUri(file_create_url($video_uri));
$relative_url = file_url_transform_relative(file_create_url($video_uri));
$video_items[] = Url::fromUserInput($relative_url);
}
$elements[] = [
'#theme' => 'video_player_formatter',
Expand All @@ -52,7 +53,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
];
return $elements;
}

/**
* {@inheritdoc}
*/
Expand All @@ -61,20 +62,8 @@ public static function isApplicable(FieldDefinitionInterface $field_definition)
return TRUE;
}
else{
$form_mode = 'default';
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load($field_definition->getTargetEntityTypeId() . '.' . $field_definition->getTargetBundle() . '.' . $form_mode);
if (!$entity_form_display) {
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->create([
'targetEntityType' => $field_definition->getTargetEntityTypeId(),
'bundle' => $field_definition->getTargetBundle(),
'mode' => $form_mode,
'status' => TRUE,
]);
}
#$entity_form_display = entity_get_form_display($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
$entity_form_display= \Drupal::service('entity_display.repository')->getFormDisplay($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
$widget = $entity_form_display->getRenderer($field_definition->getName());
if ($widget) {
$widget_id = $widget->getBaseId();
Expand Down
108 changes: 108 additions & 0 deletions src/Plugin/Field/FieldFormatter/VideoUrlFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?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;
}
}
Loading