Problem/Motivation

The unique field validation works for EntityForm, even when you want to create a media entity, but. the media library uses the class FileUploadForm, that class has not a method getEntity, and we get an error from the media library using the unique field.

Error: Call to undefined method Drupal\media_library\Form\FileUploadForm::getEntity() in unique_content_field_validation_validate_unique() (line 231 of /app/web/modules/contrib/unique_content_field_validation/unique_content_field_validation.module)

Steps to reproduce

Install the module unique_field_ajax
Go to structure/media/fields create a new text field named "test"
Enable unique value on that field
Go to structure/ content types, add a new field named media to the basic content type
Go to structure/ content types / basic page, manage form display, the new field "media" should use the widget "Media Library"
Go to node/add/page, try to add a media using the media library and the unique field in the media library form.

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

sergiogsanchez created an issue. See original summary.

sergiogsanchez’s picture

Version: 2.1.1 » 2.x-dev
StatusFileSize
new2.24 KB
sergiogsanchez’s picture

Version: 2.x-dev » 2.1.1
StatusFileSize
new2.13 KB
sergiogsanchez’s picture

Status: Active » Needs review

Eli.Stone made their first commit to this issue’s fork.

3li’s picture

Version: 2.1.1 » 2.x-dev

3li’s picture

Re-rolled onto 2.x and created a MR.
Have not tested it yet, would be good to try and write some tests specially for media library support.

3li’s picture

Assigned: sergiogsanchez » Unassigned
jidrone’s picture

Status: Needs review » Reviewed & tested by the community

I have use this patch for more than a year and it is working ok.

daniel.pernold’s picture

StatusFileSize
new2.5 KB

Reroll latest patch for 2.x and checking if there is a entity to avoid null references for getEntityTypeId().

  • 3li committed 1b81b622 on 2.x
    Issue #3249516: Media library support
    
3li’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.