I have a form that accepts a custom argument sourceid
public function buildForm(array $form, FormStateInterface $form_state, $sourceid = NULL)
Now, this form is displayed in a twig template multiple times using a for loop. For each instance of this form the sourceid is different in the twig template. The value of the sourceid is present in the twig template. Can I pass it to the form from the twig template itself? Or should I modify my controller and render the form in the template along with the id?
Code in the twig template displaying the form is as follows:
{% for item in field %}
{% if item.content %}
<p> {{ item.content|raw }} </p>
<p> {{ item.sourceid|raw }} </p>
<div>{{ metadata_form }}</div>
{% endif %}
(% endfor %}
The variable metadata_form
has the form element in it.