Issue #2969691 by thejacer87, matthieuscarset, lhangea, rwohleb, alexpott: Muted attribute not working for Video file

merge-requests/1119/head
Alex Pott 2019-05-02 18:21:34 +01:00
parent 955ffc8c50
commit cbb7ef070a
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
2 changed files with 41 additions and 1 deletions

View File

@ -151,7 +151,7 @@ abstract class FileMediaFormatterBase extends FileFormatterBase implements FileM
*/
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);
}

View File

@ -55,4 +55,44 @@ class FileVideoFormatterTest extends FileMediaFormatterTestBase {
$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']");
}
}