July 2017
Intermediate to advanced
456 pages
11h 32m
English
Many of the AJAX functions in Drupal 8 are very similar to how they were handled in Drupal 7. The major difference is in how the actual callbacks are triggered. Since forms are now classes, the #submit and #ajax attributes need to have callable values instead of just function names. As an example, let's take the configuration form from earlier and allow users to add multiple URLs. The first thing we do is to construct the wrapper around our list of URLs:
public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('mastering_drupal_8.settings'); $form['vals'] = array( '#type' => 'details', '#title' => $this->t('Rows'), '#open' => TRUE, ); // Wrapper around rows $form['vals']['rows'] = array( ...Read now
Unlock full access