Commit cbb7ef07 authored by alexpott's avatar alexpott

Issue #2969691 by thejacer87, matthieuscarset, lhangea, rwohleb, alexpott:...

Issue #2969691 by thejacer87, matthieuscarset, lhangea, rwohleb, alexpott: Muted attribute not working for Video file
parent 955ffc8c
......@@ -151,7 +151,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
*/
protected function prepareAttributes(array $additional_attributes = []) {
$attributes = new Attribute();
foreach (['controls', 'autoplay', 'loop'] + $additional_attributes as $attribute) {
foreach (array_merge(['controls', 'autoplay', 'loop'], $additional_attributes) as $attribute) {
if ($this->getSetting($attribute)) {
$attributes->setAttribute($attribute, $attribute);
}
......
......@@ -55,4 +55,44 @@ public function testRender($tag_count, $formatter_settings) {
$assert_session->elementExists('css', "video > source[src='$file2_url'][type='video/mp4']");
}
/**
* Tests that the attributes added to the formatter are applied on render.
*/
public function testAttributes() {
$field_config = $this->createMediaField(
'file_video',
'mp4',
[
'autoplay' => TRUE,
'loop' => TRUE,
'muted' => TRUE,
]
);
file_put_contents('public://file.mp4', str_repeat('t', 10));
$file = File::create([
'uri' => 'public://file.mp4',
'filename' => 'file.mp4',
]);
$file->save();
$entity = EntityTest::create([
$field_config->getName() => [
[
'target_id' => $file->id(),
],
],
]);
$entity->save();
$this->drupalGet($entity->toUrl());
$file_url = file_url_transform_relative(file_create_url($file->getFileUri()));
$assert_session = $this->assertSession();
$assert_session->elementExists('css', "video[autoplay='autoplay'] > source[src='$file_url'][type='video/mp4']");
$assert_session->elementExists('css', "video[loop='loop'] > source[src='$file_url'][type='video/mp4']");
$assert_session->elementExists('css', "video[muted='muted'] > source[src='$file_url'][type='video/mp4']");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment