- Issue created by @SirClickALot
- 🇩🇪Germany jurgenhaas Gottmadingen
You can use the eca_render sub-module which allows you to define your own endpoints (a.k.a. routes) as ECA events that are the start of an ECA model. You need to define the endpoint, and you also have to have a second event to control the access on that endpoint.
You can then use the eca_render sub-module you create a link which sends the request as an ajax request, so that you don't even leave the current page.
In the ECA endpoint you can use all the available Ajax commands that Drupal provides to even modify content in the frontend when the request completes and sends back those ajax commands.
- 🇬🇧United Kingdom SirClickALot Somerset
Got it, thanks @jurgenhaas, that's very helpful.
We were floundering around with the
Controller found to handle request
event and going around in circles.I think I get what you are saying here and we'll give that good go later, thanks again.
Moving things forward, and from the point of view of the school of 'empowering site builders', would it be possible (valuable?) in the future to provide a built-in core event that could wire this altogether for on one hit much like the old Rule Link module years ago - that was such an easy win for those who don't want to get their hands dirty a the route/entity level?
- 🇬🇧United Kingdom SirClickALot Somerset
Thanks again @jurgenhaas, I had tried to follow your advice but I'm just not quite getting it right.
I do apologise for being a bit thick here but I'm getting there.
Please note that the screenshot here is simply to aid my explanation, I have exported the ECA with as few dependencies as possible.
I have created a simple model which:
- Responds to the URL path of :
/node/automark
- Picks off a NID from the query string
- Outputs a simple Drupal message essentially simply to verify that it's responded
The actual exported model is attached below.
Using view on my usual site-builder-preferred way, I've created a good old block which spurts out...
<a href="/eca/node/automark?nid={{ raw_arguments.nid }}" class="use-ajax btn btn-sm btn-outline-secondary"> AI-assisted assessment </a>
That gives me a useful little button...
So far so good, it all works as expected but I when click the rendered link, I get the expect AJAX throbber for a second then...
The Console detailing...
POST http://bit-by-bit.local/eca/node/automark?nid=8786&_wrapper_format=drupal_ajax 404 (Not Found) send @ jquery.min.js?v=3.7.1:2 ajax @ jquery.min.js?v=3.7.1:2 Drupal.Ajax.eventResponse @ ajax.js?v=10.4.6:799 (anonymous) @ ajax.js?v=10.4.6:646 dispatch @ jquery.min.js?v=3.7.1:2 v.handle @ jquery.min.js?v=3.7.1:2 ajax.js?v=10.4.6:196 Uncaught Drupal.AjaxError {message: '\nAn AJAX HTTP error occurred.\nHTTP Result Code: 40…tatusText: Not Found\nResponseText: {"message":""}', name: 'AjaxError', stack: 'Error\n at http://bit-by-bit.local/core/misc/aja…it-by-bit.local/core/misc/ajax.js?v=10.4.6:1935:3'} (anonymous) @ ajax.js?v=10.4.6:196 (anonymous) @ ajax.js?v=10.4.6:1935
On refreshing the browser page, I do get the see the Drupal message originating from the ECA to I can confirm that it is responding to the path but I don't understand what the 404 error is referring to!
I know I'm missing a trick here and I understand that it's probably something to do with me not returning a valid AJAX response - I tried adding an EVA AJAX Response message but to no avail.
If you are able to see what I'm missing I would be most grateful because I've search far and wide for a actual step-by-step example of what I'm trying to do and the likes of the various LLMs out there just seem make up a load of rubbish ;-(
Ideally, where I want to end up is...
Having called another ECA from within this one (which actually performs the assessment and is all built and working fine),
I would simply like the current page to refresh revealing the newly-populated field.Thanks
- Responds to the URL path of :
- 🇬🇧United Kingdom SirClickALot Somerset
@jurgenhaas,
UPDATE!
After much experimenting, I seem to have made some progress here and I think I now see what you meant by...
...you also have to have a second event to control the access on that endpoint.
...
Although what I have added is an
Action
not andEvent
, no?At first I thought it seemed implicit that I would need access that if I wanted to respond to that path but I guess in another scenario, I want to BLOCK access and that's why either way, I do need to add the
Set access
result action?So, unless anyone tells me that I've got it a all wrong and that, while it works, what I have done is a fudge, I think I'm all good but maybe we should leave this open for anyone else who may be wrangling with the scenario.
Having got over this hurdle, I then immediately hit another but I will document that elsewhere.
Thank you for your support in this.
- 🇮🇪Ireland marksmith
There is an ECA Endpoint event and an another ECA Endpoint Access event, which both should be added as documented in this issue 💬 Endpoint ajax examples Active . Also the ECA endpoint path argument should explicitly begin with
/eca
and can hold up to 2 parameters, as documented in this video.Unfortunately, I am also stuck at creating a working AJAX example with these events. So, please, do post your solution if you have found one. A working documentation of AJAX functions richly represented in ECA would help many users, I believe.
- 🇩🇪Germany jurgenhaas Gottmadingen
If you go to the ECA Endpoint response documentation, there are currently 3 backlinks in the right sidebar which get you to sample models that use the endpoint logic. Maybe that helps for future questions like this.
When it comes to the proper Ajax link in the front end, you may want to use the Render: link action to render a link and add that to a page, a node, a view, a form, or anything else that's renderable. In the field
Link type
you can useAjax request
and that's all you need. If you still want to hard-code such links or buttons elsewhere, you can look into the generated markup by ECA and then re-use that elsewhere. Automatically closed - issue fixed for 2 weeks with no activity.