I am currently developing a module with a custom content type. In the node/add for this content type, I need to be insert a form that can retrieves data from an API, that will later be displayed on the page.

What is the best way to insert that form into the node/add page?

Should I use a hook_form_alter? Or should I make a custom field? This portion of the form will most likely involve AJAX, so I don't know if that will change anything.

Let me know if I need to clarify anything, and thanks in advance!


Whether you create a custom field then modify it later, or create it completely in code, you need to use hook_form_alter in your custom module and add/edit your field that way and add the ajax call inside this function.

If you create a custom field in config, then there's now a config dependency you will need to somehow move from your dev environment to production (either thru Features or Configuration modules). On the other hand, if you add all through your custom module you won't need to worry about config changes, so IMO that is a better way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.