I'm building a custom form in Drupal 9, which has some ajax callbacks.
buildForm I need to load some extra data via a rest call to an external service, which then I put inside a
I'd like to avoid to call the rest end-point during the ajax callbacks, and rely on the stored variable.
However, I can't find a way to differentiate between the "load page" case and the "ajax case". Is it possible?
I've found this answer that seems to generally work:
// Example for brevity only, inject the request_stack service and call // getCurrentRequest() on it to get the request object if possible. $request = \Drupal::request(); $is_ajax = $request->isXmlHttpRequest();
But I'd like to know if there's some helper\solution using the form API.