0

I am attempting to create/read nodes from a JS file (the nodes are created in response to Js events from a library). The PHP functions to create/read the nodes have been created and require field data as parameters. How can I run these functions from a JS file and pass the required data as parameters? I am willing to relocate/rewrite the functions in a new PHP file if required.

  • I cannot use routing/controllers/API endpoints as I would need to pass parameters as slugs - some parameters are strings and may contain slashes which are not supported by routing
  • The generation and submission of data is based on a JS library rather than Drupal forms, so I cannot use Drupal Ajax forms and pass my parameters through that. Without forms, Ajax callbacks have no support for parameters.
  • I am not sure if this Ajax request is an option with Drupal - if it is, how would I structure the 'url' in the Ajax request to get a certain php file from my module?
3
  • It seems like everything is pointing to you wanting to do this outside of Drupal - at which point it’s just php and Ajax right? With the php file bootstrapping Drupal so you can access nodes?
    – Clive
    Commented Feb 22, 2021 at 17:49
  • Thank you Clive, that seems like the best option at this point. If I add a new php file to my module, do you know how I would be able to refer to that file from js (i.e my third point in the post)?
    – P.J
    Commented Feb 22, 2021 at 18:58
  • Found it, thank you very much for your help
    – P.J
    Commented Feb 22, 2021 at 22:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.