Build a form dynamically with the results of a view? I'm working on a view block in which I load several nodes.
I don't know how many nodes will be loaded because it depends on an exposed filter.
I have twig file for the display, I also have a twigExtension php file to call custom functions.

For example, the output of my view looks like this :

Reference  
ABCD  
BCDE  
CDEF  


I would like to get a form :  

Reference | Quantity (Select dropdown)
ABCD | 0
BCDE | 1
CDEF | 0
&lt;Submit Button&gt;


Once the user clicks on the Submit Button, it creates 3 nodes of a Custom Content Type.

The lead I'm investigating for now is to use a form but I don't know how I could pass the results to this form, build it with these results and get something like :

public function buildForm(array $form, FormStateInterface $form_state) {  
    $form['ref_1'] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; t('Reference 1'),
        '#default_value' =&gt; 'ABCD'
        '#attributes' =&gt; array('readonly' =&gt; 'readonly')
    );
    $form['quantity_1'] = array(
        '#type' =&gt; 'select',
        '#title' =&gt; t('Quantity 1'),
        '#options' =&gt; array('00', '01', '02', '03'),
    );

    $form['ref_2'] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; t('Reference 2'),
        '#default_value' =&gt; 'BCDE'
        '#attributes' =&gt; array('readonly' =&gt; 'readonly')
    );
    $form['quantity_2'] = array(
        '#type' =&gt; 'select',
        '#title' =&gt; t('Quantity 2'),
        '#options' =&gt; array('00', '01', '02', '03'),
    );

    $form['ref_3'] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; t('Reference 3'),
        '#default_value' =&gt; 'CDEF'
        '#attributes' =&gt; array('readonly' =&gt; 'readonly')
    );
    $form['quantity_3'] = array(
        '#type' =&gt; 'select',
        '#title' =&gt; t('Quantity 3'),
        '#options' =&gt; array('00', '01', '02', '03'),
    );

    $form['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; t('Submit'),
    );

    return $form;
}


Or maybe should I look at the exposed filter function, maybe is there a way to modify the way it works to call my own function before display ?

How would you do it ?

Thanks.
Build the custom form from inside the view and attach it to the view before rendering:

mymodule.module

/**
 * Implements hook_views_pre_render().
 */
function mymodule_views_pre_render($view) {
  if ($view-&gt;id() == 'myview') {
    // get field values from the view result
    $values = [];
    foreach ($view-&gt;result as $row_id =&gt; $row) {
      foreach ($view-&gt;field as $field_id =&gt; $field ) {
        $values[$row_id][$field_id] = $field-&gt;getValue($row);
      }
    }
    // build form with the view result
    $form = \Drupal::formBuilder()-&gt;getForm('Drupal\mymodule\Form\MyForm', $values);
    // attach the form to the view
    $view-&gt;attachment_after = $form;
  }
}


Use the view result for building the form:

/src/Form/MyForm.php

class MyForm extends FormBase {

  public function buildForm(array $form, FormStateInterface $form_state, array $values = NULL) {
    // build form with $values
  }