Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 2.0.x
  • 8.x-1.x
  • 2.0.0
  • 2.0.1
  • 2.0.2
  • 8.X-1.0-beta1
  • 8.x-1.0
  • 8.x-1.0-beta1
  • 8.x-1.0-beta2
  • 8.x-1.0-beta3
  • 8.x-1.0-beta4
  • 8.x-1.0-beta5
  • 8.x-1.1
  • 8.x-1.2
  • 8.x-1.x-beta3
15 results

Target

Select target project
  • project/video_embed_html5
  • issue/video_embed_html5-2886164
  • issue/video_embed_html5-3347969
  • issue/video_embed_html5-3393182
  • issue/video_embed_html5-3435354
  • issue/video_embed_html5-3457755
  • issue/video_embed_html5-3481090
  • issue/video_embed_html5-3522910
8 results
Select Git revision
  • 3347969-fatal-error-if
  • 8.x-1.x
  • 8.X-1.0-beta1
  • 8.x-1.0
  • 8.x-1.0-beta1
  • 8.x-1.0-beta2
  • 8.x-1.0-beta3
  • 8.x-1.0-beta4
  • 8.x-1.0-beta5
  • 8.x-1.1
  • 8.x-1.2
  • 8.x-1.x-beta3
  • previous/3347969-fatal-error-if/2023-05-11
13 results
Show changes
Commits on Source (9)
################
# DrupalCI GitLabCI template
#
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
#
# With thanks to:
# * The GitLab Acceleration Initiative participants
# * DrupalSpoons
################
################
# Guidelines
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
#
# However, you can modify this template if you have additional needs for your project.
################
################
# Includes
#
# Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
#
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################
include:
################
# DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
################
- project: $_GITLAB_TEMPLATES_REPO
# "ref" value can be:
# - Recommended (default) - `ref: $_GITLAB_TEMPLATES_REF` - The Drupal Association will update this value to the recommended tag for contrib.
# - Latest - `ref: main` - Get the latest additions and bug fixes as they are merged into the templates.
# - Minor or Major latests - `ref: 1.x-latest` or `ref: 1.0.x-latest` - Get the latest additions within a minor (mostly bugfixes) or major (bugs and new features).
# - Fixed tag - `ref: 1.0.1` - Set the value to a known tag. This will not get any updates.
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
################
# Pipeline configuration variables
#
# These are the variables provided to the Run Pipeline form that a user may want to override.
#
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml
################
variables:
# OPT_IN_TEST_PREVIOUS_MAJOR: 1
OPT_IN_TEST_PREVIOUS_MINOR: 1
OPT_IN_TEST_NEXT_MINOR: 1
# OPT_IN_TEST_NEXT_MAJOR: 1
OPT_IN_TEST_MAX_PHP: 1
_CSPELL_WORDS: 'colorbox, webm'
_PHPUNIT_CONCURRENT: 1
###################################################################################
#
# *
# /(
# ((((,
# /(((((((
# ((((((((((*
# ,(((((((((((((((
# ,(((((((((((((((((((
# ((((((((((((((((((((((((*
# *(((((((((((((((((((((((((((((
# ((((((((((((((((((((((((((((((((((*
# *(((((((((((((((((( .((((((((((((((((((
# ((((((((((((((((((. /(((((((((((((((((*
# /((((((((((((((((( .(((((((((((((((((,
# ,(((((((((((((((((( ((((((((((((((((((
# .(((((((((((((((((((( .(((((((((((((((((
# ((((((((((((((((((((((( ((((((((((((((((/
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
# *((((((((((((( .((((((((((((((( ,(((((((((((((
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
# *((((((((((((((((((((( (((((((((((((((((((((,
# ,(((((((((((((((((((((, ((((((((((((((((((((/
# ,(((((((((((((((((((((* /((((((((((((((((((((
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
# .(((((((((((((((((((((((((((((((((((((((((((((
# .((((((((((((((((((((((((((((((((((((,.
# .,(((((((((((((((((((((((((.
#
###################################################################################
This module add support for embedding HTML5 videos into your website using Video Embed Field This module add support for embedding HTML5 videos into your website using
Video Embed Field
## Installation ## Installation
...@@ -12,10 +13,13 @@ To install this module, do the following: ...@@ -12,10 +13,13 @@ To install this module, do the following:
1. Install module 1. Install module
2. Add video embed field and enable "HTML5" provider 2. Add video embed field and enable "HTML5" provider
3. Add link that ends with mp4/ogg/webm 3. Add link that ends with mp4/ogg/webm
## Generating thumbnails ## Generating thumbnails
There are two ways you can generate thumbnails for a HTML5 video: There are two ways you can generate thumbnails for a HTML5 video:
1. On server side: using the [php_ffmpeg module](https://www.drupal.org/project/php_ffmpeg). This requires you to configure the module properly 1. On server side: using the [php_ffmpeg module](https://www.drupal.org/project/php_ffmpeg).
and add the dependent binaries. This requires you to configure the module properly and add the dependent
2. On client side: if, for some reason, you are unable to use the above (preferred) solution. The thumbnails can be created on page load. binaries.
A new CANVAS object will be created which uses the first frame of the video as a thumbnail. 2. On client side: if, for some reason, you are unable to use the above (
preferred) solution. The thumbnails can be created on page load.
A new CANVAS object will be created which uses the first frame of the video as
a thumbnail.
...@@ -4,10 +4,15 @@ ...@@ -4,10 +4,15 @@
"type": "drupal-module", "type": "drupal-module",
"homepage": "https://www.drupal.org/project/video_embed_html5", "homepage": "https://www.drupal.org/project/video_embed_html5",
"license": "GPL-2.0+", "license": "GPL-2.0+",
"extra": { "require": {
"drupal": { "php": ">=8.0",
"package": " Video Embed Field", "drupal/video_embed_field": "^2.5",
"version": "8.x-1.x" "drupal/core": "^9.2 || ^10 || ^11"
} },
"require-dev": {
"drupal/php_ffmpeg": "1.x-dev"
},
"suggest": {
"drupal/php_ffmpeg": "For server side generation of video thumbnails"
} }
} }
add_placeholder: true add_placeholder: true
placeholder: null placeholder: null
\ No newline at end of file
canvas { canvas {
max-width: 100%; max-width: 100%;
height: auto; height: auto;
} }
\ No newline at end of file
(function ($) { (function ($) {
var mapping = {}; const mapping = {};
$('div[data-render-thumbnail]').each(function (index) { $('div[data-render-thumbnail]').each(function (index) {
$this = $(this); const $this = $(this);
var id = $this.attr('id'); const id = $this.attr('id');
// Create video element. // Create video element.
var video = document.createElement('video'); const video = document.createElement('video');
video.preload = 'auto'; video.preload = 'auto';
video.src = $this.attr('data-render-thumbnail'); video.src = $this.attr('data-render-thumbnail');
// Add to array of videos. // Add to array of videos.
mapping[id] = {video: video, element: $this}; mapping[id] = { video, element: $this };
}); });
$.each(mapping, function (index, value) { $.each(mapping, function (index, value) {
var video = value.video; const video = value.video;
$element = value.element;
video.addEventListener('loadeddata', function () { video.addEventListener(
// This fires the "seeked" event. 'loadeddata',
video.currentTime = 10; function () {
}, false); // This fires the "seeked" event.
video.currentTime = 10;
},
false,
);
video.addEventListener('seeked', function () { video.addEventListener(
// Create new canvas of frame in video. 'seeked',
var c = document.createElement("canvas"); function () {
c.width = video.videoWidth; // Create new canvas of frame in video.
c.height = video.videoHeight; const c = document.createElement('canvas');
c.getContext('2d').drawImage(video, 0, 0, video.videoWidth, video.videoHeight); c.width = video.videoWidth;
// Add canvas to dom. c.height = video.videoHeight;
$(mapping[index].element).html(c); c.getContext('2d').drawImage(
video,
}, false); 0,
0,
video.videoWidth,
video.videoHeight,
);
// Add canvas to dom.
$(mapping[index].element).html(c);
},
false,
);
}); });
})(jQuery); })(jQuery);
\ No newline at end of file
...@@ -2,30 +2,36 @@ ...@@ -2,30 +2,36 @@
namespace Drupal\video_embed_html5\Form; namespace Drupal\video_embed_html5\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\file\Entity\File;
use Drupal\file\FileInterface;
use Drupal\file\FileUsage\FileUsageInterface; use Drupal\file\FileUsage\FileUsageInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Class VideoEmbedHtml5ConfigForm * Configuration form for Video Embed HTML5.
*
* @package Drupal\video_embed_html5\Form * @package Drupal\video_embed_html5\Form
*/ */
class VideoEmbedHtml5ConfigForm extends ConfigFormBase { class VideoEmbedHtml5ConfigForm extends ConfigFormBase {
protected $fileUsage;
/** /**
* VideoEmbedHtml5ConfigForm constructor. * VideoEmbedHtml5ConfigForm constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* @param \Drupal\file\FileUsage\FileUsageInterface $file_usage * The factory for configuration objects.
* @param \Drupal\file\FileUsage\FileUsageInterface $fileUsage
* The file usage service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
*/ */
public function __construct(ConfigFactoryInterface $config_factory, FileUsageInterface $file_usage) { public function __construct(
ConfigFactoryInterface $config_factory,
protected FileUsageInterface $fileUsage,
protected EntityTypeManagerInterface $entityTypeManager,
) {
parent::__construct($config_factory); parent::__construct($config_factory);
$this->fileUsage = $file_usage;
} }
/** /**
...@@ -34,28 +40,29 @@ class VideoEmbedHtml5ConfigForm extends ConfigFormBase { ...@@ -34,28 +40,29 @@ class VideoEmbedHtml5ConfigForm extends ConfigFormBase {
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('config.factory'), $container->get('config.factory'),
$container->get('file.usage') $container->get('file.usage'),
$container->get('entity_type.manager')
); );
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getFormId() { public function getFormId(): string {
return 'video_embed_html5_config_form'; return 'video_embed_html5_config_form';
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getEditableConfigNames() { public function getEditableConfigNames(): array {
return ['video_embed_html5.config']; return ['video_embed_html5.config'];
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state): array {
$config = $this->config('video_embed_html5.config'); $config = $this->config('video_embed_html5.config');
$form['add_placeholder'] = [ $form['add_placeholder'] = [
...@@ -75,14 +82,13 @@ class VideoEmbedHtml5ConfigForm extends ConfigFormBase { ...@@ -75,14 +82,13 @@ class VideoEmbedHtml5ConfigForm extends ConfigFormBase {
'#default_value' => $config->get('placeholder'), '#default_value' => $config->get('placeholder'),
]; ];
return parent::buildForm($form, $form_state); return parent::buildForm($form, $form_state);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state): void {
$config = $this->config('video_embed_html5.config'); $config = $this->config('video_embed_html5.config');
$config->set('add_placeholder', $form_state->getValue('add_placeholder')); $config->set('add_placeholder', $form_state->getValue('add_placeholder'));
$config->set('placeholder', $form_state->getValue('placeholder')); $config->set('placeholder', $form_state->getValue('placeholder'));
...@@ -90,16 +96,15 @@ class VideoEmbedHtml5ConfigForm extends ConfigFormBase { ...@@ -90,16 +96,15 @@ class VideoEmbedHtml5ConfigForm extends ConfigFormBase {
if (!empty($form_state->getValue('placeholder')[0])) { if (!empty($form_state->getValue('placeholder')[0])) {
// Record this module as using this file. // Record this module as using this file.
/** @var FileInterface $placeholder */ /** @var \Drupal\file\FileInterface $placeholder */
$placeholder = File::load($form_state->getValue('placeholder')[0]); $placeholder = $this->entityTypeManager->getStorage('file')->load($form_state->getValue('placeholder')[0]);
$references = $this->fileUsage->listUsage($placeholder); $references = $this->fileUsage->listUsage($placeholder);
if (empty($references)) { if (empty($references)) {
$this->fileUsage->add($placeholder, 'video_embed_html5', 'settings', 0); $this->fileUsage->add($placeholder, 'video_embed_html5', 'settings', 0);
} }
} }
parent::submitForm($form, $form_state); parent::submitForm($form, $form_state);
} }
} }
\ No newline at end of file
...@@ -3,11 +3,10 @@ ...@@ -3,11 +3,10 @@
namespace Drupal\video_embed_html5\Plugin\video_embed_field\Provider; namespace Drupal\video_embed_html5\Plugin\video_embed_field\Provider;
use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\File\FileSystemInterface; use Drupal\Core\File\FileSystemInterface;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
use Drupal\file\FileInterface;
use Drupal\image\Entity\ImageStyle;
use Drupal\video_embed_field\ProviderPluginBase; use Drupal\video_embed_field\ProviderPluginBase;
use FFMpeg\Coordinate\TimeCode; use FFMpeg\Coordinate\TimeCode;
use FFMpeg\FFMpeg; use FFMpeg\FFMpeg;
...@@ -24,39 +23,68 @@ use Symfony\Component\DependencyInjection\ContainerInterface; ...@@ -24,39 +23,68 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/ */
class Html5 extends ProviderPluginBase { class Html5 extends ProviderPluginBase {
/** @var FFMpeg $phpFFMpeg */ /**
protected $phpFFMpeg; * The video_embed_field config.
protected $fileSystem; *
protected $config; * @var \Drupal\Core\Config\ImmutableConfig
protected $videoUrl; */
protected $filename; protected ImmutableConfig $config;
protected $videoType;
/**
* The video Url.
*
* @var string
*/
protected string $videoUrl = '';
/**
* The File name.
*
* @var string
*/
protected string $filename = '';
/**
* The Video type.
*
* @var string
*/
protected string $videoType = '';
/** /**
* Html5 constructor. * Html5 constructor.
* @param string $configuration *
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id * @param string $plugin_id
* @param array $plugin_definition * The id of the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \GuzzleHttp\ClientInterface $http_client * @param \GuzzleHttp\ClientInterface $http_client
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The Guzzle HTTP client.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
* @param \Drupal\Core\Extension\ModuleExtensionList $moduleExtensionList
* The module extension list service.
* @param \FFMpeg\FFMpeg|null $phpFfmpeg
* The optional PHP FFMPEG service.
*
* @throws \Exception
*/ */
public function __construct($configuration, $plugin_id, array $plugin_definition, public function __construct(
ClientInterface $http_client, ModuleHandlerInterface $module_handler, array $configuration,
FileSystemInterface $file_system, ConfigFactoryInterface $config_factory) { string $plugin_id,
$plugin_definition,
ClientInterface $http_client,
ConfigFactoryInterface $config_factory,
protected ModuleExtensionList $moduleExtensionList,
protected ?FFMpeg $phpFfmpeg,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $http_client); parent::__construct($configuration, $plugin_id, $plugin_definition, $http_client);
$this->phpFFMpeg = FALSE;
if ($module_handler->moduleExists('php_ffmpeg')) {
$this->phpFFMpeg = \Drupal::service('php_ffmpeg');
}
$this->fileSystem = $file_system;
$this->config = $config_factory->get('video_embed_html5.config'); $this->config = $config_factory->get('video_embed_html5.config');
// Set filename for thumbnail. // Set filename for thumbnail.
list($video_url, $video_type) = $this->getVideoId(); [$video_url, $video_type] = $this->getVideoId();
$this->videoUrl = $video_url; $this->videoUrl = $video_url;
$this->videoType = $video_type; $this->videoType = $video_type;
$this->filename = md5($video_url); $this->filename = md5($video_url);
...@@ -66,22 +94,33 @@ class Html5 extends ProviderPluginBase { ...@@ -66,22 +94,33 @@ class Html5 extends ProviderPluginBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static( $phpFfmpeg = NULL;
$module_handler = $container->get('module_handler');
if ($module_handler->moduleExists('php_ffmpeg')) {
try {
$phpFfmpeg = $container->get('php_ffmpeg');
}
catch (\Exception $e) {
// Do nothing.
}
}
$instance = new static(
$configuration, $configuration,
$plugin_id, $plugin_id,
$plugin_definition, $plugin_definition,
$container->get('http_client'), $container->get('http_client'),
$container->get('module_handler'), $container->get('config.factory'),
$container->get('file_system'), $container->get('extension.list.module'),
$container->get('config.factory') $phpFfmpeg
); );
return $instance;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function renderEmbedCode($width, $height, $autoplay) { public function renderEmbedCode($width, $height, $autoplay): array {
// @todo: test with colorbox formatter. // @todo test with colorbox formatter.
return [ return [
'#theme' => 'video_embed_html5', '#theme' => 'video_embed_html5',
'#src' => $this->videoUrl, '#src' => $this->videoUrl,
...@@ -94,17 +133,18 @@ class Html5 extends ProviderPluginBase { ...@@ -94,17 +133,18 @@ class Html5 extends ProviderPluginBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function downloadThumbnail() { public function downloadThumbnail(): void {
if ($this->phpFFMpeg) { if ($this->phpFfmpeg) {
$local_uri = $this->getLocalThumbnailUri(); $local_uri = $this->getLocalThumbnailUri();
if (!file_exists($local_uri)) { if (!file_exists($local_uri)) {
$this->fileSystem->prepareDirectory($this->thumbsDirectory, FileSystemInterface::CREATE_DIRECTORY); $this->getFileSystem()->prepareDirectory($this->thumbsDirectory, FileSystemInterface::CREATE_DIRECTORY);
try { try {
// Thumb does not exist yet. Generate it. // Thumb does not exist yet. Generate it.
$video = $this->phpFFMpeg->open($this->videoUrl); $video = $this->phpFfmpeg->open($this->videoUrl);
$video->frame(TimeCode::fromSeconds(1)) $video->frame(TimeCode::fromSeconds(1))
->save($this->fileSystem->realpath($this->thumbsDirectory) . '/' . $this->filename . '.jpg'); ->save($this->getFileSystem()->realpath($this->thumbsDirectory) . '/' . $this->filename . '.jpg');
} catch (\Exception $e) { }
catch (\Exception $e) {
} }
} }
} }
...@@ -113,31 +153,31 @@ class Html5 extends ProviderPluginBase { ...@@ -113,31 +153,31 @@ class Html5 extends ProviderPluginBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getLocalThumbnailUri() { public function getLocalThumbnailUri(): string {
return $this->thumbsDirectory . '/' . $this->filename . '.jpg'; return $this->thumbsDirectory . '/' . $this->filename . '.jpg';
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getRemoteThumbnailUrl() { public function getRemoteThumbnailUrl(): string {
// Don't need this as we override "downloadThumbnail". // Don't need this as we override "downloadThumbnail".
return FALSE; return '';
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function renderThumbnail($image_style, $link_url) { public function renderThumbnail($image_style, $link_url): array {
$build = parent::renderThumbnail($image_style, $link_url); $build = parent::renderThumbnail($image_style, $link_url);
if (!file_exists($this->getLocalThumbnailUri()) && !$this->phpFFMpeg) { if (!file_exists($this->getLocalThumbnailUri()) && !$this->phpFfmpeg) {
// Set uri to default placeholder. // Set uri to default placeholder.
$uri = \Drupal::service('extension.list.module')->getPath('video_embed_html5') . '/img/placeholder.png'; $uri = $this->moduleExtensionList->getPath('video_embed_html5') . '/img/placeholder.png';
if ($this->config->get('add_placeholder')) { if ($this->config->get('add_placeholder')) {
if (($file = $this->config->get('placeholder')) && ($file = File::load($file[0]))) { if (($file = $this->config->get('placeholder')) && ($file = File::load($file[0]))) {
// Custom placeholder is uploaded, use this one. // Custom placeholder is uploaded, use this one.
/** @var FileInterface $file */ /** @var \Drupal\file\FileInterface $file */
$uri = $file->getFileUri(); $uri = $file->getFileUri();
} }
} }
...@@ -189,14 +229,25 @@ class Html5 extends ProviderPluginBase { ...@@ -189,14 +229,25 @@ class Html5 extends ProviderPluginBase {
*/ */
public static function getIdFromInput($input) { public static function getIdFromInput($input) {
$pattern = "/(?:(\/)|(?:(?|http|https|ftp)(?|\/\/))).*(mp4|ogg|webm)/i"; $pattern = "/(?:(\/)|(?:(?|http|https|ftp)(?|\/\/))).*(mp4|ogg|webm)/i";
$matches = array(); $matches = [];
preg_match($pattern, $input, $matches); preg_match($pattern, $input, $matches);
// Make sure there are values. // Make sure there are values.
if ($matches && isset($matches[2])) { if ($matches && isset($matches[2])) {
return array($input, $matches[2]); return [$input, $matches[2]];
} }
return FALSE; return FALSE;
} }
/**
* {@inheritdoc}
*/
public function getName() {
return $this->t('@provider Video (@id)', [
'@provider' => $this->getPluginDefinition()['title'],
'@id' => $this->getVideoId()[0],
]);
}
} }
<video controls {{ autoplay ? 'autoplay' : '' }} width="100%"> <video controls {{ autoplay ? 'muted autoplay' : '' }} width="100%">
<source src="{{ src }}" type="{{ type }}"/> <source src="{{ src }}" type="{{ type }}"/>
</video> </video>
\ No newline at end of file
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Drupal\Tests\video_embed_html5\Unit; namespace Drupal\Tests\video_embed_html5\Unit;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
use Drupal\video_embed_brightcove\Plugin\video_embed_field\Provider\Brightcove;
use Drupal\video_embed_html5\Plugin\video_embed_field\Provider\Html5; use Drupal\video_embed_html5\Plugin\video_embed_field\Provider\Html5;
/** /**
...@@ -14,6 +13,8 @@ use Drupal\video_embed_html5\Plugin\video_embed_field\Provider\Html5; ...@@ -14,6 +13,8 @@ use Drupal\video_embed_html5\Plugin\video_embed_field\Provider\Html5;
class ProviderUrlParseTest extends UnitTestCase { class ProviderUrlParseTest extends UnitTestCase {
/** /**
* Public function testUrlParsing.
*
* @dataProvider urlsWithExpectedIds * @dataProvider urlsWithExpectedIds
* *
* Test URL parsing works as expected. * Test URL parsing works as expected.
...@@ -28,13 +29,13 @@ class ProviderUrlParseTest extends UnitTestCase { ...@@ -28,13 +29,13 @@ class ProviderUrlParseTest extends UnitTestCase {
* @return array * @return array
* An array of test cases. * An array of test cases.
*/ */
public function urlsWithExpectedIds() { public function urlsWithExpectedIds(): array {
return [ return [
'HTML5 video' => [ 'HTML5 video' => [
'https://www.html5rocks.com/en/tutorials/video/basics/devstories.mp4', 'https://www.html5rocks.com/en/tutorials/video/basics/devstories.mp4',
[ [
'https://www.html5rocks.com/en/tutorials/video/basics/devstories.mp4', 'https://www.html5rocks.com/en/tutorials/video/basics/devstories.mp4',
'mp4' 'mp4',
], ],
], ],
'No HTML5 video' => [ 'No HTML5 video' => [
...@@ -43,4 +44,5 @@ class ProviderUrlParseTest extends UnitTestCase { ...@@ -43,4 +44,5 @@ class ProviderUrlParseTest extends UnitTestCase {
], ],
]; ];
} }
} }
name: Video Embed HTML5 name: Video Embed HTML5
type: module type: module
description: Embed HTML5 videos into your website using Video Embed Field. description: Embed HTML5 videos into your website using Video Embed Field.
core_version_requirement: ^8 || ^9 || ^10 core_version_requirement: ^9.2 || ^10 || ^11
package: Video Embed Field package: Video Embed Field
dependencies: dependencies:
- video_embed_field:video_embed_field - video_embed_field:video_embed_field
configure: video_embed_html5.config.form configure: video_embed_html5.config.form
<?php <?php
/**
* @file
* Video Embed HTML5 Module Install File.
*/
/** /**
* Add default configuration to Video Embed HTML5. * Add default configuration to Video Embed HTML5.
*/ */
...@@ -9,4 +14,4 @@ function video_embed_html5_update_8001() { ...@@ -9,4 +14,4 @@ function video_embed_html5_update_8001() {
$config->set('add_placeholder', TRUE); $config->set('add_placeholder', TRUE);
$config->set('placeholder', NULL); $config->set('placeholder', NULL);
$config->save(TRUE); $config->save(TRUE);
} }
\ No newline at end of file
<?php <?php
/**
* @file
* Video Embed HTML5 Module File.
*/
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
/** /**
* Implements hook_help(). * Implements hook_help().
*/ */
function video_embed_html5_help($route_name, RouteMatchInterface $route_match) { function video_embed_html5_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) { if ($route_name == 'help.page.video_embed_html5') {
case 'help.page.video_embed_html5': $output = file_get_contents(\Drupal::service('extension.list.module')->getPath('video_embed_html5') . '/README.md');
$output = file_get_contents(\Drupal::service('extension.list.module')->getPath('video_embed_html5') . '/README.md'); return '<pre>' . $output . '</pre>';
return '<pre>' . $output . '</pre>';
break;
default:
} }
} }
......