summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobin.ingelbrecht2017-06-09 16:59:41 +0800
committerSam2017-06-09 16:59:41 +0800
commit7283bca1b9d89622cf94314316ed2d53113317f8 (patch)
tree95b0f95bbc91269e74e1be44e174e19131693dd9
parent9eff6313041033cf2c9380ff047a50abddde5c36 (diff)
Issue #2870151 by robin.ingelbrecht, Sam152: Add class of provider on ".video-embed-field-responsive-video" level
-rw-r--r--modules/video_embed_wysiwyg/src/Plugin/Filter/VideoEmbedWysiwyg.php17
-rw-r--r--modules/video_embed_wysiwyg/tests/src/Kernel/FilterTest.php12
-rw-r--r--src/Plugin/Field/FieldFormatter/Video.php15
-rw-r--r--src/ProviderPluginInterface.php3
-rw-r--r--tests/modules/video_embed_field_mock_provider/src/Plugin/video_embed_field/Provider/MockProvider.php14
-rw-r--r--tests/src/FunctionalJavascript/ColorboxFormatterTest.php2
-rw-r--r--tests/src/Kernel/FieldOutputTest.php236
7 files changed, 187 insertions, 112 deletions
diff --git a/modules/video_embed_wysiwyg/src/Plugin/Filter/VideoEmbedWysiwyg.php b/modules/video_embed_wysiwyg/src/Plugin/Filter/VideoEmbedWysiwyg.php
index 7334122..f0c50e7 100644
--- a/modules/video_embed_wysiwyg/src/Plugin/Filter/VideoEmbedWysiwyg.php
+++ b/modules/video_embed_wysiwyg/src/Plugin/Filter/VideoEmbedWysiwyg.php
@@ -2,6 +2,7 @@
namespace Drupal\video_embed_wysiwyg\Plugin\Filter;
+use Drupal\Component\Utility\Html;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\filter\FilterProcessResult;
@@ -89,18 +90,20 @@ class VideoEmbedWysiwyg extends FilterBase implements ContainerFactoryPluginInte
$autoplay = $this->currentUser->hasPermission('never autoplay videos') ? FALSE : $embed_data['settings']['autoplay'];
$embed_code = $provider->renderEmbedCode($embed_data['settings']['width'], $embed_data['settings']['height'], $autoplay);
+ $embed_code = [
+ '#type' => 'container',
+ '#attributes' => [
+ 'class' => [Html::cleanCssIdentifier(sprintf('video-embed-field-provider-%s', $provider->getPluginId()))],
+ ],
+ 'children' => $embed_code,
+ ];
+
// Add the container to make the video responsive if it's been
// configured as such. This usually is attached to field output in the
// case of a formatter, but a custom container must be used where one is
// not present.
if ($embed_data['settings']['responsive']) {
- $embed_code = [
- '#type' => 'container',
- '#attributes' => [
- 'class' => ['video-embed-field-responsive-video'],
- ],
- 'children' => $embed_code,
- ];
+ $embed_code['#attributes']['class'][] = 'video-embed-field-responsive-video';
}
// Replace the JSON settings with a video.
diff --git a/modules/video_embed_wysiwyg/tests/src/Kernel/FilterTest.php b/modules/video_embed_wysiwyg/tests/src/Kernel/FilterTest.php
index a04ec4e..417236c 100644
--- a/modules/video_embed_wysiwyg/tests/src/Kernel/FilterTest.php
+++ b/modules/video_embed_wysiwyg/tests/src/Kernel/FilterTest.php
@@ -47,23 +47,23 @@ class FilterTest extends KernelTestBase {
return [
'Standard embed code' => [
'<p>Content.</p><p>{"preview_thumbnail":"http://example.com/thumbnail.jpg","video_url":"https://www.youtube.com/watch?v=uNRtZDAS0xI","settings":{"responsive":1,"width":"854","height":"480","autoplay":1},"settings_summary":["Embedded Video (854x480, autoplaying)."]}</p><p>More content.</p>',
- '<p>Content.</p><div class="video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/uNRtZDAS0xI?autoplay=1&amp;start=0&amp;rel=0"></iframe></div><p>More content.</p>',
+ '<p>Content.</p><div class="video-embed-field-provider-youtube video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/uNRtZDAS0xI?autoplay=1&amp;start=0&amp;rel=0"></iframe></div><p>More content.</p>',
],
'Embedded vimeo video' => [
'<p>Content.</p><p>{"preview_thumbnail":"http://example.com/thumbnail.jpg","video_url":"https://vimeo.com/18352872","settings":{"responsive":1,"width":"854","height":"480","autoplay":1},"settings_summary":["Embedded Video (854x480, autoplaying)."]}</p><p>More content.</p>',
- '<p>Content.</p><div class="video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/18352872?autoplay=1"></iframe></div><p>More content.</p>',
+ '<p>Content.</p><div class="video-embed-field-provider-vimeo video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/18352872?autoplay=1"></iframe></div><p>More content.</p>',
],
'JSON keys in reverse order' => [
'<p>Content.</p><p>{"settings_summary":["Embedded Video (854x480, autoplaying)."],"settings":{"responsive":1,"width":"854","height":"480","autoplay":1},"video_url":"https://vimeo.com/18352872","preview_thumbnail":"http://example.com/thumbnail.jpg"}</p><p>More content.</p>',
- '<p>Content.</p><div class="video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/18352872?autoplay=1"></iframe></div><p>More content.</p>',
+ '<p>Content.</p><div class="video-embed-field-provider-vimeo video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/18352872?autoplay=1"></iframe></div><p>More content.</p>',
],
'Relative thumbnail URL' => [
'<p>Content.</p><p>{"settings_summary":["Embedded Video (854x480, autoplaying)."],"settings":{"responsive":1,"width":"854","height":"480","autoplay":1},"video_url":"https://vimeo.com/18352872","preview_thumbnail":"/thumbnail.jpg"}</p><p>More content.</p>',
- '<p>Content.</p><div class="video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/18352872?autoplay=1"></iframe></div><p>More content.</p>',
+ '<p>Content.</p><div class="video-embed-field-provider-vimeo video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/18352872?autoplay=1"></iframe></div><p>More content.</p>',
],
'No wrapping paragraphs tags' => [
'{"settings_summary":["Embedded Video (854x480, autoplaying)."],"settings":{"responsive":1,"width":"854","height":"480","autoplay":1},"video_url":"https://vimeo.com/18352872","preview_thumbnail":"/thumbnail.jpg"}',
- '<div class="video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/18352872?autoplay=1"></iframe></div>',
+ '<div class="video-embed-field-provider-vimeo video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/18352872?autoplay=1"></iframe></div>',
],
'Invalid URL' => [
'<p>Content.</p><p>{"preview_thumbnail":"http://example.com/thumbnail.jpg","video_url":"https://example.com/InvalidUrl","settings":{"responsive":1,"width":"854","height":"480","autoplay":1},"settings_summary":["Embedded Video (854x480, autoplaying)."]}</p><p>More content.</p>',
@@ -79,7 +79,7 @@ class FilterTest extends KernelTestBase {
],
'XSS Width/Height' => [
'<p>Content.</p><p>{"preview_thumbnail":"http://example.com/thumbnail.jpg","video_url":"https://www.youtube.com/watch?v=uNRtZDAS0xI","settings":{"responsive":1,"width":"\">test","height":"\">test","autoplay":1},"settings_summary":["Embedded Video (854x480, autoplaying)."]}</p><p>More content.</p>',
- '<p>Content.</p><div class="video-embed-field-responsive-video"><iframe width="&quot;&gt;test" height="&quot;&gt;test" frameborder="0" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/uNRtZDAS0xI?autoplay=1&amp;start=0&amp;rel=0"></iframe></div><p>More content.</p>',
+ '<p>Content.</p><div class="video-embed-field-provider-youtube video-embed-field-responsive-video"><iframe width="&quot;&gt;test" height="&quot;&gt;test" frameborder="0" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/uNRtZDAS0xI?autoplay=1&amp;start=0&amp;rel=0"></iframe></div><p>More content.</p>',
],
'Empty settings' => [
'<p>Content.</p><p>{"preview_thumbnail":"http://example.com/thumbnail.jpg","video_url":"https://www.youtube.com/watch?v=uNRtZDAS0xI","settings":{},"settings_summary":["Embedded Video (854x480, autoplaying)."]}</p><p>More content.</p>',
diff --git a/src/Plugin/Field/FieldFormatter/Video.php b/src/Plugin/Field/FieldFormatter/Video.php
index 152b524..361207a 100644
--- a/src/Plugin/Field/FieldFormatter/Video.php
+++ b/src/Plugin/Field/FieldFormatter/Video.php
@@ -2,6 +2,7 @@
namespace Drupal\video_embed_field\Plugin\Field\FieldFormatter;
+use Drupal\Component\Utility\Html;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
@@ -100,14 +101,16 @@ class Video extends FormatterBase implements ContainerFactoryPluginInterface {
$element[$delta] = $provider->renderEmbedCode($this->getSetting('width'), $this->getSetting('height'), $autoplay);
$element[$delta]['#cache']['contexts'][] = 'user.permissions';
+ $element[$delta] = [
+ '#type' => 'container',
+ '#attributes' => ['class' => [Html::cleanCssIdentifier(sprintf('video-embed-field-provider-%s', $provider->getPluginId()))]],
+ 'children' => $element[$delta],
+ ];
+
// For responsive videos, wrap each field item in it's own container.
if ($this->getSetting('responsive')) {
- $element[$delta] = [
- '#type' => 'container',
- '#attached' => ['library' => ['video_embed_field/responsive-video']],
- '#attributes' => ['class' => ['video-embed-field-responsive-video']],
- 'children' => $element[$delta],
- ];
+ $element[$delta]['#attached']['library'][] = 'video_embed_field/responsive-video';
+ $element[$delta]['#attributes']['class'][] = 'video-embed-field-responsive-video';
}
}
diff --git a/src/ProviderPluginInterface.php b/src/ProviderPluginInterface.php
index 7020c64..863feeb 100644
--- a/src/ProviderPluginInterface.php
+++ b/src/ProviderPluginInterface.php
@@ -1,11 +1,12 @@
<?php
namespace Drupal\video_embed_field;
+use Drupal\Component\Plugin\PluginInspectionInterface;
/**
* Providers an interface for embed providers.
*/
-interface ProviderPluginInterface {
+interface ProviderPluginInterface extends PluginInspectionInterface {
/**
* Check if the plugin is applicable to the user input.
diff --git a/tests/modules/video_embed_field_mock_provider/src/Plugin/video_embed_field/Provider/MockProvider.php b/tests/modules/video_embed_field_mock_provider/src/Plugin/video_embed_field/Provider/MockProvider.php
index 58115e0..da282f7 100644
--- a/tests/modules/video_embed_field_mock_provider/src/Plugin/video_embed_field/Provider/MockProvider.php
+++ b/tests/modules/video_embed_field_mock_provider/src/Plugin/video_embed_field/Provider/MockProvider.php
@@ -74,4 +74,18 @@ class MockProvider implements ProviderPluginInterface {
return 'Video Name';
}
+ /**
+ * {@inheritdoc}
+ */
+ public function getPluginId() {
+ return 'foo';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getPluginDefinition() {
+ return [];
+ }
+
}
diff --git a/tests/src/FunctionalJavascript/ColorboxFormatterTest.php b/tests/src/FunctionalJavascript/ColorboxFormatterTest.php
index 685b1a1..d9b9496 100644
--- a/tests/src/FunctionalJavascript/ColorboxFormatterTest.php
+++ b/tests/src/FunctionalJavascript/ColorboxFormatterTest.php
@@ -3,6 +3,7 @@
namespace Drupal\Tests\video_embed_field\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
+use Drupal\local_testing\LocalTestingTrait;
use Drupal\Tests\video_embed_field\Functional\EntityDisplaySetupTrait;
/**
@@ -13,6 +14,7 @@ use Drupal\Tests\video_embed_field\Functional\EntityDisplaySetupTrait;
class ColorboxFormatterTest extends JavascriptTestBase {
use EntityDisplaySetupTrait;
+ use LocalTestingTrait;
/**
* {@inheritdoc}
diff --git a/tests/src/Kernel/FieldOutputTest.php b/tests/src/Kernel/FieldOutputTest.php
index 4836892..1e5316e 100644
--- a/tests/src/Kernel/FieldOutputTest.php
+++ b/tests/src/Kernel/FieldOutputTest.php
@@ -58,23 +58,31 @@ class FieldOutputTest extends KernelTestBase {
],
],
[
- '#type' => 'video_embed_iframe',
- '#provider' => 'youtube',
- '#url' => 'https://www.youtube.com/embed/fdbFVWupSsw',
- '#query' => [
- 'autoplay' => '1',
- 'start' => '0',
- 'rel' => '0',
- ],
+ '#type' => 'container',
'#attributes' => [
- 'width' => '100',
- 'height' => '100',
- 'frameborder' => '0',
- 'allowfullscreen' => 'allowfullscreen',
+ 'class' => [
+ 'video-embed-field-provider-youtube',
+ ],
],
- '#cache' => [
- 'contexts' => [
- 'user.permissions',
+ 'children' => [
+ '#type' => 'video_embed_iframe',
+ '#provider' => 'youtube',
+ '#url' => 'https://www.youtube.com/embed/fdbFVWupSsw',
+ '#query' => [
+ 'autoplay' => '1',
+ 'start' => '0',
+ 'rel' => '0',
+ ],
+ '#attributes' => [
+ 'width' => '100',
+ 'height' => '100',
+ 'frameborder' => '0',
+ 'allowfullscreen' => 'allowfullscreen',
+ ],
+ '#cache' => [
+ 'contexts' => [
+ 'user.permissions',
+ ],
],
],
],
@@ -91,23 +99,31 @@ class FieldOutputTest extends KernelTestBase {
],
],
[
- '#type' => 'video_embed_iframe',
- '#provider' => 'youtube',
- '#url' => 'https://www.youtube.com/embed/fdbFVWupSsw',
- '#query' => [
- 'autoplay' => '1',
- 'start' => '100',
- 'rel' => '0',
- ],
+ '#type' => 'container',
'#attributes' => [
- 'width' => '100',
- 'height' => '100',
- 'frameborder' => '0',
- 'allowfullscreen' => 'allowfullscreen',
+ 'class' => [
+ 'video-embed-field-provider-youtube',
+ ],
],
- '#cache' => [
- 'contexts' => [
- 'user.permissions',
+ 'children' => [
+ '#type' => 'video_embed_iframe',
+ '#provider' => 'youtube',
+ '#url' => 'https://www.youtube.com/embed/fdbFVWupSsw',
+ '#query' => [
+ 'autoplay' => '1',
+ 'start' => '100',
+ 'rel' => '0',
+ ],
+ '#attributes' => [
+ 'width' => '100',
+ 'height' => '100',
+ 'frameborder' => '0',
+ 'allowfullscreen' => 'allowfullscreen',
+ ],
+ '#cache' => [
+ 'contexts' => [
+ 'user.permissions',
+ ],
],
],
],
@@ -124,24 +140,32 @@ class FieldOutputTest extends KernelTestBase {
],
],
[
- '#type' => 'video_embed_iframe',
- '#provider' => 'youtube',
- '#url' => 'https://www.youtube.com/embed/fdbFVWupSsw',
- '#query' => [
- 'autoplay' => '1',
- 'start' => '0',
- 'rel' => '0',
- 'cc_lang_pref' => 'fr',
- ],
+ '#type' => 'container',
'#attributes' => [
- 'width' => '100',
- 'height' => '100',
- 'frameborder' => '0',
- 'allowfullscreen' => 'allowfullscreen',
+ 'class' => [
+ 'video-embed-field-provider-youtube',
+ ],
],
- '#cache' => [
- 'contexts' => [
- 'user.permissions',
+ 'children' => [
+ '#type' => 'video_embed_iframe',
+ '#provider' => 'youtube',
+ '#url' => 'https://www.youtube.com/embed/fdbFVWupSsw',
+ '#query' => [
+ 'autoplay' => '1',
+ 'start' => '0',
+ 'rel' => '0',
+ 'cc_lang_pref' => 'fr',
+ ],
+ '#attributes' => [
+ 'width' => '100',
+ 'height' => '100',
+ 'frameborder' => '0',
+ 'allowfullscreen' => 'allowfullscreen',
+ ],
+ '#cache' => [
+ 'contexts' => [
+ 'user.permissions',
+ ],
],
],
],
@@ -169,21 +193,29 @@ class FieldOutputTest extends KernelTestBase {
],
],
[
- '#type' => 'video_embed_iframe',
- '#provider' => 'vimeo',
- '#url' => 'https://player.vimeo.com/video/80896303',
- '#query' => [
- 'autoplay' => '1',
- ],
+ '#type' => 'container',
'#attributes' => [
- 'width' => '100',
- 'height' => '100',
- 'frameborder' => '0',
- 'allowfullscreen' => 'allowfullscreen',
+ 'class' => [
+ 'video-embed-field-provider-vimeo',
+ ],
],
- '#cache' => [
- 'contexts' => [
- 'user.permissions',
+ 'children' => [
+ '#type' => 'video_embed_iframe',
+ '#provider' => 'vimeo',
+ '#url' => 'https://player.vimeo.com/video/80896303',
+ '#query' => [
+ 'autoplay' => '1',
+ ],
+ '#attributes' => [
+ 'width' => '100',
+ 'height' => '100',
+ 'frameborder' => '0',
+ 'allowfullscreen' => 'allowfullscreen',
+ ],
+ '#cache' => [
+ 'contexts' => [
+ 'user.permissions',
+ ],
],
],
],
@@ -200,22 +232,30 @@ class FieldOutputTest extends KernelTestBase {
],
],
[
- '#type' => 'video_embed_iframe',
- '#provider' => 'vimeo',
- '#url' => 'https://player.vimeo.com/video/80896303',
- '#query' => [
- 'autoplay' => '1',
- ],
- '#fragment' => 't=150s',
+ '#type' => 'container',
'#attributes' => [
- 'width' => '100',
- 'height' => '100',
- 'frameborder' => '0',
- 'allowfullscreen' => 'allowfullscreen',
+ 'class' => [
+ 'video-embed-field-provider-vimeo',
+ ],
],
- '#cache' => [
- 'contexts' => [
- 'user.permissions',
+ 'children' => [
+ '#type' => 'video_embed_iframe',
+ '#provider' => 'vimeo',
+ '#url' => 'https://player.vimeo.com/video/80896303',
+ '#query' => [
+ 'autoplay' => '1',
+ ],
+ '#fragment' => 't=150s',
+ '#attributes' => [
+ 'width' => '100',
+ 'height' => '100',
+ 'frameborder' => '0',
+ 'allowfullscreen' => 'allowfullscreen',
+ ],
+ '#cache' => [
+ 'contexts' => [
+ 'user.permissions',
+ ],
],
],
],
@@ -265,7 +305,7 @@ class FieldOutputTest extends KernelTestBase {
[
'#type' => 'container',
'#attributes' => [
- 'data-video-embed-field-modal' => '<iframe width="500" height="500" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/80896303?autoplay=1"></iframe>',
+ 'data-video-embed-field-modal' => '<div class="video-embed-field-provider-vimeo"><iframe width="500" height="500" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/80896303?autoplay=1"></iframe></div>',
'class' => ['video-embed-field-launch-modal'],
],
'#attached' => [
@@ -305,7 +345,7 @@ class FieldOutputTest extends KernelTestBase {
[
'#type' => 'container',
'#attributes' => [
- 'data-video-embed-field-modal' => '<div class="video-embed-field-responsive-video video-embed-field-responsive-modal" style="width:999px;"><iframe width="900" height="450" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/80896303?autoplay=1"></iframe></div>',
+ 'data-video-embed-field-modal' => '<div class="video-embed-field-provider-vimeo video-embed-field-responsive-video video-embed-field-responsive-modal" style="width:999px;"><iframe width="900" height="450" frameborder="0" allowfullscreen="allowfullscreen" src="https://player.vimeo.com/video/80896303?autoplay=1"></iframe></div>',
'class' => [
'video-embed-field-launch-modal',
],
@@ -348,7 +388,10 @@ class FieldOutputTest extends KernelTestBase {
'library' => ['video_embed_field/responsive-video'],
],
'#attributes' => [
- 'class' => ['video-embed-field-responsive-video'],
+ 'class' => [
+ 'video-embed-field-provider-vimeo',
+ 'video-embed-field-responsive-video'
+ ],
],
'children' => [
'#type' => 'video_embed_iframe',
@@ -383,21 +426,29 @@ class FieldOutputTest extends KernelTestBase {
],
],
[
- '#type' => 'video_embed_iframe',
- '#provider' => 'youtube_playlist',
- '#url' => 'https://www.youtube.com/embed/videoseries',
- '#query' => [
- 'list' => 'PLpeDXSh4nHjQCIZmkxg3VSdpR5e87X5eB',
- ],
+ '#type' => 'container',
'#attributes' => [
- 'width' => '100',
- 'height' => '100',
- 'frameborder' => '0',
- 'allowfullscreen' => 'allowfullscreen',
+ 'class' => [
+ 'video-embed-field-provider-youtube-playlist',
+ ],
],
- '#cache' => [
- 'contexts' => [
- 'user.permissions',
+ 'children' => [
+ '#type' => 'video_embed_iframe',
+ '#provider' => 'youtube_playlist',
+ '#url' => 'https://www.youtube.com/embed/videoseries',
+ '#query' => [
+ 'list' => 'PLpeDXSh4nHjQCIZmkxg3VSdpR5e87X5eB',
+ ],
+ '#attributes' => [
+ 'width' => '100',
+ 'height' => '100',
+ 'frameborder' => '0',
+ 'allowfullscreen' => 'allowfullscreen',
+ ],
+ '#cache' => [
+ 'contexts' => [
+ 'user.permissions',
+ ],
],
],
],
@@ -482,9 +533,10 @@ class FieldOutputTest extends KernelTestBase {
$entity->{$this->fieldName}->value = $url;
$entity->save();
- $field_output = $this->container->get('renderer')->executeInRenderContext(new RenderContext(), function() use ($entity, $settings) {
- return $entity->{$this->fieldName}->view($settings);
- });
+ $field_output = $this->container->get('renderer')
+ ->executeInRenderContext(new RenderContext(), function () use ($entity, $settings) {
+ return $entity->{$this->fieldName}->view($settings);
+ });
// Prepare the field output to make it easier to compare our test data
// values against.