I have a form I have a field of type Date Range, I also have another field of type entity_browser(modal) with a selection view widget.
The normal behavior when I click the Button of the entity browser field, is the opening of the modal, if we inspect the code it can be seen similar to this:
<form data-entity-browser-uuid="a9b7680318c9f1a1aca1abc308d8c6d0ac880b4a" data-drupal-selector="entity-browser-event-browser-form" action="/entity-browser/modal/event_browser?uuid=a9b7680318c9f1a1aca1abc308d8c6d0ac880b4a&original_path=/node/add/activity" method="post" id="entity-browser-event-browser-form">.... </form>
What I’m trying to do, is that as the dates are selected, pass these values as arguments to the iframe url something like this:
<form action="/entity-browser/modal/event_browser?uuid=a9b7680318c9f1a1aca1abc308d8c6d0ac880b4&aoriginal_path=/node/add/activity&start=12-02-2022&end=14-02-2022" .... </form>
Then from the view take these values and filter the contents.
What i have so far
Reviewing the code of the entity_browser module, I see that the Modal class (Drupalentity_browserPluginEntityBrowserDisplayModal
), as part of the process hook, this dispatch an event to which one can subscribe.
In fact, i can add parameters to the query argument in this subscription, i have harcoded the values as a test, but they do not render when I refresh the form where I create the content that contains the entity_browser type field.
Example:
public function onAlterEntityBrowserDisplayData(AlterEntityBrowserDisplayData $event) { if ($event->getBrowserID() === "event_browser") { $data = $event->getData(); if (isset($data["query_parameters"]["query"])) { $data["query_parameters"]["query"]['start'] = '12-02-2022'; $data["query_parameters"]["query"]['end'] = '14-02-2022'; $event->setData($data); } } }
If I could get this to work, then I’d have to figure out some way with ajax to keep changing these values as the values in the date field change.
I don’t know if this is the best way to do it, I don’t know what you think.