How can I have default field values for the node add form as arguments in the URL?

I have a path in drupal 6, which allow me to add new content with 2 fields completed. For example, path node/add/my_content_type/4/6 means that I am on page /node/add/my_content_type, and first field has value “Philip” and second field has value “Oleg”. Those names are in database, because user put them in in another content type.

I try to do the same in Drupal 8, but I cannot put arguments after /mycontent_type/. So right now, on the /node/add/my_content_type I see a form with fields, I can select names in input select, but nothing shows when I put more arguments in url.

I will give an example:

I have a module with students and school trip. On custom content “students”, I add students names in text input. Those names are saved in database.

Let’s say, that my second content type is “trip”.
I have a function, which allow me to add a trip, when students names are given. I can simply click add content ‘trip’ and select names in select fields, but I want to make it more simple and redirect to page /node/add/trip/4/6 where 4 is id of “Philip” and 6 is id of “Oleg”. In this way I have a form with to fields already completed. It is posible in drupal 6, but no in drupal 8. Have can i do that?

I think that one of the problem could be the fact, that Drupal 8 require field “Title”. So I have to modify url a little bit /node/add/trip/??TITLE??/4/6.

I need exactly this -> https://www.drupal.org/forum/support/module-development-and-code-questions/2020-04-27/webform-field-default-value-from-url
but for custom content 🙂


Go to Source of this post
Author Of this post: newbe
Title Of post: How can I have default field values for the node add form as arguments in the URL?
Author Link: {authorlink}