/**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $form = parent::buildConfigurationForm($form, $form_state);
     // Only allow selecting the layout when creating a new variant.
     if (empty($this->configuration['layout'])) {
         $form['layout'] = ['#title' => $this->t('Layout'), '#type' => 'select', '#options' => $this->layoutManager->getLayoutOptions(array('group_by_category' => TRUE))];
     } else {
         $form['layout'] = ['#type' => 'value', '#value' => $this->configuration['layout']];
         // If a layout is already selected, show the layout settings.
         $form['layout_settings_wrapper'] = ['#type' => 'fieldset', '#title' => $this->t('Layout settings')];
         $form['layout_settings_wrapper']['layout_settings'] = [];
         // Get settings form from layout plugin.
         $layout = $this->layoutManager->createInstance($this->configuration['layout'], $this->configuration['layout_settings'] ?: []);
         $form['layout_settings_wrapper']['layout_settings'] = $layout->buildConfigurationForm($form['layout_settings_wrapper']['layout_settings'], $form_state);
         // Process callback to configure #parents correctly on settings, since
         // we don't know where in the form hierarchy our settings appear.
         $form['#process'][] = [$this, 'layoutSettingsProcessCallback'];
     }
     return $form;
 }