Problem/Motivation
When user loads an entity browser form we load generate UUID of a so-called entity browser instance. This UUID allows us to differentiate between multiple instances on the same page.
Some display plugins need UUID information even before the form was generated (in DisplayInterface::displayEntityBrowser()). It seems that we'll need to generate UUID earlier in some cases.
Proposed resolution
One solution was proposed until now - better solutions welcome. We could generate UUID in DisplayInterface::displayEntityBrowser() and pass it on to the form via URL argument. Form would then check if the UUID already exists and generate it only if not.
Original issue summary
In both the Modal and IFrame Display plugins, the REGISTER_JS_CALLBACKS event is dispatched and RegisterJSCallbacks objects are created without passing the required $instance_uuid argument. I would submit a patch but I'm not sure where we can get an instance UUID for the Entity Browser (I believe it's abstracted from the Display Plugin). The relevant calls are in Modal::displayEntityBrowser() and IFrame::displayEntityBrowser().
Comment | File | Size | Author |
---|---|---|---|
#17 | interdiff.txt | 2.08 KB | slashrsm |
#17 | 2600706_17.patch | 17.14 KB | slashrsm |
#16 | interdiff.txt | 2.57 KB | slashrsm |
#16 | 2600706_16.patch | 16.42 KB | slashrsm |
#14 | 2600706_14.patch | 15.46 KB | slashrsm |
Comments
Comment #2
samuel.mortensonSubmitted https://github.com/drupal-media/entity_browser/pull/107
Comment #3
slashrsm CreditAttribution: slashrsm at Examiner.com commentedInstance UUID is now stored in form state. See: https://github.com/drupal-media/entity_browser/blob/8.x-1.x/src/Form/Ent...
Comment #4
samuel.mortensonAs the Events::REGISTER_JS_CALLBACKS event is dispatched before the form is rendered, what's the best way to handle this? Pass another generated UUID?
Comment #5
rackberg CreditAttribution: rackberg as a volunteer commentedMaybe this will fix it: https://github.com/drupal-media/entity_browser/pull/110
Comment #6
samuel.mortensonThat suffers the same problem if I understand correctly - the UUID you're passing isn't the instance_uuid (which is generated in the form).
Comment #7
slashrsm CreditAttribution: slashrsm as a volunteer commentedLooking at the code it seems that we don't even read the UUID property anywhere. Could we just remove it from event constructor?
Even if we do that we still have problem of two different UUIDs for a given instance (one generated in display plugin and one generated in form class). General code flow usually goes something like this:
1. EB is loaded and DisplayInterface::displayEntityBrowser() is called to get initial representation of EB.
2. User interacts with initial representation.
3. Actual EB form is build and displayed to the user. When this first happens form class generated UUID.
4. ...
We could change step 4 a bit. It could check if UUID was passed through URL and use that instead of generating new one. This would re-use UUID that was generated in DisplayInterface::displayEntityBrowser() and also work for display that don't generate it (standalone).
How does that sound? Is there any security aspect of this that we should consider.
Comment #9
slashrsm CreditAttribution: slashrsm at Examiner.com commentedI decided to merge #2 as it fixes fatal. Added a comment to explain that is a temp change and linked it back to this issue: https://github.com/drupal-media/entity_browser/commit/21d6b493818d86b839...
Leaving this open until we resolve issues from #7.
Updating issue summary.
Comment #10
samuel.mortensonI think this is a good option, providing the instance UUID early on in the process so that the Browser and Form can take advantage of it. On the other hand, if we don't actually know why we're using an instance UUID in the first place, we might consider removing it.
Comment #11
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedHere we go.
Comment #14
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedComment #15
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedTypo.
Hmm, is there no better way to get uuid then using superglobal?
Can we inject this
We can remove contains in Drupal\entity_browser\Plugin\EntityBrowser\Display\Standard
Comment #16
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedComment #17
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedInjected uuid.
Comment #18
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedLooks great.
Comment #19
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commented