Send data from controller to hook_form_alter() I created a module for searching movies in different external databases.
I use the Drupal node add page to handle the insertion of the movie. Now I need to know a way to send the data from my custom controller to the /node/add/movies_movie page.

In the controller I use the following code to send data to the module page.

if ($system === "IMDB") {
    $database = new ImdbDatabase;
    $movie = $database-&gt;getDataById($id);

    $tempstore = \Drupal::service('user.private_tempstore')-&gt;get('movies');
    $tempstore-&gt;set("newMovie", $movie);
}

$option = [
    'guid' =&gt; $guid,
];

$url = Url::fromUri('internal:/node/add/movies_movie');

return $this-&gt;redirect(
    $url-&gt;getRouteName(),
    $url-&gt;getRouteParameters(),
    $url-&gt;getOptions(),
    302
);


My hook gets the value using the private tempstore service:

function movies_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
{
    if($form_id === 'node_movies_movie_form')
    {
        //$movie = null;

        $storage = $form_state-&gt;getStorage();

        $tempstore = \Drupal::service('user.private_tempstore')-&gt;get('movies');
        $movie = $tempstore-&gt;get('newMovie');


I use hook_form_alter()to place the objects inside the add form. How can I send data from my controller to hook_form_alter() to place the custom values on the form?

To better understand my problem I will explain my situation in normal English without any technical terms.

The site contains a page to search to movies using a search bar. It will show the result of all the movies in a table with an add button after each movie. When pressing on a add button it will get all the data from the movie and will automaticly place the received movie data, in the movie insertion form. On the movie insertion form can be user change all the values and save it.
I think you should not load the data in your controller but in your hook_form_alter. Redirect the user to a path containing a query parameter in Url, so that the url may look like "http://www.yoursite.com/node/add/movies_movie?guid=123" and change the guid paramter to the value of the movie.

Then in your hook_form_alter:

$request = \Drupal::request();
$guid = $request-&gt;query-&gt;get('guid');

if ($system === "IMDB" &amp;&amp; $guid) {
    $database = new ImdbDatabase;
    $movie = $database-&gt;getDataById($guid);

    // fill in the values of the movie into the form fields
}