Skip to content
Snippets Groups Projects
Unverified Commit cbb7ef07 authored by Alex Pott's avatar Alex Pott
Browse files

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
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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']");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment