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.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3249516-11-media-library-support.patch | 2.5 KB | daniel.pernold |
| #3 | media-library-support-2.1-3249516.patch | 2.13 KB | sergiogsanchez |
Issue fork unique_field_ajax-3249516
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
Comment #2
sergiogsanchez commentedComment #3
sergiogsanchez commentedComment #4
sergiogsanchez commentedComment #6
3liComment #8
3liRe-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.
Comment #9
3liComment #10
jidrone commentedI have use this patch for more than a year and it is working ok.
Comment #11
daniel.pernold commentedReroll latest patch for 2.x and checking if there is a entity to avoid null references for getEntityTypeId().
Comment #13
3li