Issue #2969691 by thejacer87, matthieuscarset, lhangea, rwohleb, alexpott: Muted attribute not working for Video file
parent
955ffc8c50
commit
cbb7ef070a
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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']");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue