Please let me know if there is already an issue for this. It looks like AEL does not work with core media entities, at least not for the variant where the label is generated after saving the entity. The reason seems to be that the hook invoked when a media item is created is hook_entity_create(), while AEL implements hook_entity_presave(). Does this sound plausible at all?

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

eelkeblok created an issue. See original summary.

iamweird’s picture

Status: Active » Needs review
StatusFileSize
new1019 bytes

That issue occurs because core Media returns its source name when media name is not set, causing Auto Entity Label to think that label is not empty. See \Drupal\media\Entity\Media::getName() for that logic.

Attached a patch with workaround for core media entities. Probably it would be better to get label key of the entity type, but this patch at least prevents the media form from showing validation error when creating new media with empty label.

iamweird’s picture

There is still issue with patch #2 that the media label always gets overridden for optional setting, even if user enters label manually. These two patches address that issue. However, patching core is required, because core sets label for media, if it's empty, which was introduced in Move Media::save() logic into storage handler to prevent data integrity issues when media items with remote content are saved. When core issue Add entity methods and hooks for executing pre/post code outside of the save transaction is resolved, core patch will not be needed.

socialnicheguru’s picture

Status: Needs review » Needs work

The patch for auto_entitylabel no longer applies to Dev.
the core patch does apply to Drupal 9.3.18

mrinalini9’s picture

Status: Needs work » Needs review
StatusFileSize
new2.87 KB

Rerolled patch #3 for auto_entitylabel, please review it.

socialnicheguru’s picture

Do we still need to apply both patches, and auto_entitylabel and core https://www.drupal.org/files/issues/2019-09-11/drupal-media-pre-prepares... from #3 or just the patch in #5?

pmunch’s picture

Patch #5 is a reroll of #3, you just need to apply #5.
Works fine.

socialnicheguru’s picture

Status: Needs review » Needs work

No longer applies to 3.0 version

kevinquillen’s picture

Re-rolled for 3.x. Worked for me in the following scenarios:

  • Single upload at Add Media
  • Bulk upload at Add Media
  • Single upload in Media Library browser
  • Bulk upload in Media Library browser
kevinquillen’s picture

StatusFileSize
new2.79 KB

Attaching patch.

kevinquillen’s picture

Status: Needs work » Needs review
kevinquillen’s picture

Anyone know what the test failures pertain to?

lars.stiebenz’s picture

StatusFileSize
new2.15 KB

The patch is a re-roll of the one in #2965989-10: Does not work with core media against auto_entitylabel 3.3.0.
It requires the core patch from #2965989-3: Does not work with core media too: drupal-media-pre-preparesave-hook.patch
The core patch invokes a hook and the auto_entitylabel patch implements it.

Since there is still an ongoing discussion in #2992426: Add entity methods and hooks for executing pre/post code outside of the save transaction, the name of the hook might change or an event might be used instead of a hook.

socialnicheguru’s picture

deleted comment

dqd’s picture

Priority: Normal » Major
Status: Needs review » Needs work

Sorry for a late maintainer's eye on it. Bookmarked now.

Correctly stated in the comment of lars.stiebenz 2 years ago, in core issue #2992426: Add entity methods and hooks for executing pre/post code outside of the save transaction the ongoing progress is relevant for us here to now which route to go.

Important comments there:

  • Comment #9 in that issue could maybe help some users here partly on some of the related problems, and
  • Comment #10 on that issue states other (sub) issues which may need help too (for those who have time to dip into it over there).

Is anyone involved in the latest patches here able to create an MR so that we can guide users to temporarely use this as work around until we know where to go?

We also should temporarely disable the AEL tab on media or at least the batch resave option to prevent users running accidently into empty required fields on batch resave of 100s of files. That would raise this issue to Critical.

For those who try to prefill the base "name" field (the required media label): try the source mapping of media under /admin/structure/media/manage/[type] instead. It has some options which could possibly help in some cases.