'; $form['elements']['container']['second']['#suffix'] = ''; // Add an ajax callback that replaces the contents of the wrapper. $form['elements']['container']['first']['#ajax'] = [ 'callback' => [$this, 'ajaxCallback'], 'wrapper' => 'ajax-wrapper', 'event' => 'change', 'progress' => [ 'type' => 'throbber', 'message' => $this->t('Updating options...'), ], ]; // Set the view contextual filter to the value of the first element. $first_value = $form_state->getValue('first'); if ($first_value !== NULL) { $form['elements']['container']['second']['#selection_settings']['view']['arguments'][0] = $first_value; } } /** * Ajax callback to update dependent element. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @return \Drupal\Core\Ajax\AjaxResponse * The AJAX response. */ public function ajaxCallback(array $form, FormStateInterface $form_state): AjaxResponse { $response = new AjaxResponse(); $response->addCommand(new ReplaceCommand('#ajax-wrapper', $form['elements']['container']['second'])); return $response; } }