Problem/Motivation

It is currently not possible to configure an audio file using FileAudioFormatter to be muted by default.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio#Attributes

Solution

This configuration currently exists in FileVideoFormatter and works properly. Since both the audio and video formatters share FileMediaFormatterBase, moving the muted setting to that class provides this option to both formatters without breaking any existing config for videos.

Comments

jnettik created an issue. See original summary.

jnettik’s picture

Status: Active » Needs review
StatusFileSize
new4.9 KB

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

kristen pol’s picture

Thanks for the issue and patch.

1) Patch applies cleanly to 9.1.x.

2) Changes are straightforward (code is moved to higher level).

3) I see the muted option for Audio and for Video media types. See screenshots.

4) I do not see the muted option for the other media types which is as expected.

5) When I create an Audio field and a Video field after choosing muted to enabled, the controls do show up with muted control. See screenshots.

6) After disabling the muted option in the Audio/Video settings, the fields do not show up muted by default. See screenshots.

7) I'll kick off tests for 9.1.

8) Marking for tests since they probably need to be updated. See core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.php for existing Video test.

9) For some reason, at least when testing on simplytest.me, the video media field thumbnail isn't showing up so that's why it's empty in the screenshots. But I was able to use the control and could hear the audio for the video and audio media fine.

kristen pol’s picture

Fyi, regarding #4.9, this is due to a simplytest.me bug: #3162126: Image styles either aren't generated or can't be downloaded

raman.b’s picture

Assigned: jnettik » Unassigned
Status: Needs work » Needs review
StatusFileSize
new6.63 KB
new1.56 KB

Adding test for audio attributes similar to core/modules/file/tests/src/Functional/Formatter/FileVideoFormatterTest.php

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

danflanagan8’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests

I think the patch looks good and it was thoroughly tested by @Kristen Pol in #4. The test added in #6 looks great (very closely modeled after an existing core test), but it uses some recently deprecated code that needs to be updated.

+++ b/core/modules/file/tests/src/Functional/Formatter/FileAudioFormatterTest.php
@@ -60,4 +60,44 @@ public function testRender($tag_count, $formatter_settings) {
+    $file_url = file_url_transform_relative(file_create_url($file->getFileUri()));

This needs to be replaced with:

$file_url = \Drupal::service('file_url_generator')->generateString($file->getFileUri());

It should be an easy update. The patch in #6 still applies cleanly.

elber’s picture

Assigned: Unassigned » elber
elber’s picture

Assigned: elber » Unassigned
Status: Needs work » Needs review
StatusFileSize
new0 bytes
danflanagan8’s picture

Status: Needs review » Needs work

@elber, that patch was empty. Did you upload the wrong file?

ankithashetty’s picture

Status: Needs work » Needs review
StatusFileSize
new6.64 KB
new2.41 KB

Here is an updated patch, thanks!

elber’s picture

StatusFileSize
new1.74 KB

Sorry my patch is here.

Status: Needs review » Needs work

The last submitted patch, 15: 3090641-13.patch, failed testing. View results

elber’s picture

Assigned: Unassigned » elber
danflanagan8’s picture

Issue tags: +Novice

@ankithashetty, why does your patch include a change to core/modules/file/src/Plugin/Field/FieldFormatter/FileMediaFormatterBase.php? Could you explain that? It may be right, but I wasn't expecting it.

@elber, your patch only contains the new test, with none of the other changes, which is why it failed. Posting an interdiff along with your patch can make it easier to review, too. Here are instructions: https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...

It looks like we've gotten ourselves into a situation where both of you are working at the same time. Personally, I would like to see @elber finish this off since it's really a Novice issue at this point. I'll tag it as such.

But I would still like to hear from @ankithashetty about that extra change in the patch in #14. Is that something @elber should incorporate?

elber’s picture

Assigned: elber » Unassigned
Status: Needs work » Needs review
StatusFileSize
new6.64 KB
new2.41 KB
danflanagan8’s picture

Something is still really fishy with this interdiff. When I diff #6 and #18, the only change I see is the line in the test. I don't see any diff in FileMediaFormatterBase. So why is there a change shown in the interdiff? Also, I should be able to apply the interdiff as a patch on top of the patch from #6. But doing that fails. So something is wrong with the interdiff.

danflanagan8’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Novice

The patch itself though looks good. Regardless of what the interdiff says, the only change is the fix to the deprecated code in the new test. I also applied the patch in #18 locally and tested it with video and audio media. The muted configuration does what is expected for video and audio media. @Kristen Pol also did thorough testing previously.

RTBC!

Even if the use cases for muting an audio field by default are rare, I think this patch does the right thing by moving that configuration to the base formatter. If that's where autoplay is, that's where muted should be.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: 3090641-18.patch, failed testing. View results

danflanagan8’s picture

Status: Needs work » Reviewed & tested by the community

The recent failures were random fails in Layout Builder functional javascript tests, a well known issue. Unrelated to changes here. Setting back to RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: 3090641-18.patch, failed testing. View results

danflanagan8’s picture

Status: Needs work » Reviewed & tested by the community

That was a random test fail in Drupal\Tests\layout_builder\FunctionalJavascript\ContentPreviewToggleTest

Back to RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: 3090641-18.patch, failed testing. View results

danflanagan8’s picture

Status: Needs work » Reviewed & tested by the community

Those were random fails in LAyoutBuilder functional js tests. Back to RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: 3090641-18.patch, failed testing. View results

danflanagan8’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated fail. Back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

I think we need a change record here because we are changing a base class and there are quite a few implementations in contrib. For example - https://git.drupalcode.org/project/media_entity_lottie/-/blob/2.0.x/src/... - see https://git.drupalcode.org/search?group_id=2&page=3&repository_ref=&scop... for more implementations. The CR needs to cover what is going to change for these contrib modules and what they'd need to do to opt out if the player does not support it.

mrshowerman’s picture

What if we move this functionality to a new base class FileMuteableMediaFormatterBase (not quite sure about the wording) that extends FileMediaFormatterBase? That way, contrib modules aren't forced to opt out of this functionality, while they can opt in by simply extending the new class.
We will still need a change record, though.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.