Closed (fixed)
Project:
Drupal core
Version:
9.4.x-dev
Component:
media system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
29 Sep 2020 at 08:09 UTC
Updated:
9 Dec 2022 at 21:36 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
akalam commentedComment #3
akalam commentedComment #7
phenaproximaTransferring credit from #3179868: Make MediaLibraryWidget more flexible, which I closed as a duplicate of this one.
Comment #8
phenaproximaI think I'm okay with this idea, but two things come to mind:
checkAccess()permits it).target_type) which is particular to that base implementation. So it's not enough that the item list just implement the entity reference interface; it actually has to be an entity reference, or a descendant of it.Comment #9
chr.fritschAdded a test and changed to check for
EntityReferenceFieldItemListComment #10
phenaproximaThat looks pretty good, but my only major objection is to how the test is written. Adding a data provider to an existing method is not a bad idea by itself, but the method in question is testing a specific set of validation-related circumstances, as opposed to just "the media library will open with an entity reference subclass". IMHO this should be its own method, so that we can make that distinction clear. Even if it's mostly identical to an existing test. I'm open to being convinced otherwise, but if it was implemented this way for convenience, it should be its own method.
One nitpick: could you change
if (!$items instanceof EntityReferenceItemList)toif (!($items instance of EntityReferenceItemList))? I ask because it's not immediately clear if the ! is evaluated first, or theinstanceof. (You and I know that the ! is evaluated first, but the extra parentheses will make it crystal clear to those who don't have god-mode knowledge of PHP.)A request: we should have a comment above the
instanceofcheck to explain why we are looking for a concrete class, rather than an interface. Otherwise, we're guaranteed to forget why we did it that way. Something like// Check that the field is an entity reference, or subclass of it, since we need to check the target_type setting.And, one question: I'm not clear on why we need to subclass the widget, as opposed to just using
hook_field_widget_info_alter()to make the existingmedia_library_widgetwork with the new entity reference subclass (which, IMHO, is a more realistic scenario).Comment #11
phenaproximaComment #12
alexpottRe precedence and knowledge. The problem with adding the brackets is that then you're reinforcing the idea that there is a precedence issue here.
Comment #13
phenaproximaI personally find the precedence non-obvious, so I imagine others might feel similarly as well. But I'm certainly not gonna block on that. :) Totally a nitpick. 🤓 Feel free to disregard.
Comment #14
chr.fritschReverted the changed test and added a new one.
Comment #15
phenaproximaNo serious complaints here, but I'm wondering if we could clean up and/or speed up the test.
This change is unnecessary; MediaLibraryTestBase already has media_library_test in its $modules array.
Nit: should be "Tests".
Nit: extra blank line.
We don't need the entity_type or field_type properties here. We can just pass
'field_storage' => $field_storage_config, as long as $field_storage_config is the thing we created just before this. Alternately, we could streamline this even more by using EntityReferenceTestTrait::createEntityReferenceField().Why do we need the
regionandsettingsproperties?To be honest, I'm wondering if we shouldn't just make this a kernel test. It might more clearly allow us to reproduce the exception (and therefore prove the fix), and it would be faster.
Comment #16
phenaproximaHere's a patch with the same fix, but tests it by modifying an existing test. If this test fails for a field type-related reason, IMHO it will offer a clearer picture of what's going wrong. I'm open to keeping the functional JS test, though, if committers feel it's helpful.
Comment #17
seanbThe patch looks good to me. Can we add a fail patch to double check the test works as expected?
Comment #18
phenaproximaHere's a fail patch just to prove that the test covers what we think it does.
Comment #20
phenaproximaFail patch failed exactly as expected.
Comment #21
seanbLooks good to me. Nice!
Comment #22
alexpottCommitted 7064c43 and pushed to 9.4.x. Thanks!
Comment #24
alexpottI don't really think this is a feature. It's on the line between bug and task. We should always prefer interfaces over string IDs.
Comment #26
anthony.bouch commented@phenaproxima would be grateful for an explanation as to why the credit for this issue was transferred from original issue that was raised by me in 2019? Wouldn't that make this issue the duplicate? And not mine?