You are here

public function BetterFieldDescriptionsFieldsForm::submitForm in Better Field Descriptions 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

src/Form/BetterFieldDescriptionsFieldsForm.php, line 225

Class

BetterFieldDescriptionsFieldsForm
Displays the better_field_descriptions_fields settings form.

Namespace

Drupal\better_field_descriptions\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $bfd = $this
    ->config('better_field_descriptions.settings')
    ->get('better_field_descriptions');
  $template_bundle = $form_state
    ->getValue('bundles');
  $path = drupal_get_path('module', 'better_field_descriptions');
  $template = $template_bundle['template'];
  $template_uri = $path . '/templates/' . $template . '.html.twig';
  $form_state
    ->setValue([
    'bundles',
    'template_uri',
  ], $template_uri);

  // If the template is changed, do a theme registry rebuild.
  if (isset($bfd['template']) && $template != $bfd['template']) {
    drupal_theme_rebuild();
  }

  // Setting variables.
  $config = $this
    ->config('better_field_descriptions.settings')
    ->set('better_field_descriptions', $form_state
    ->getValue('bundles'));
  $config
    ->save();
  parent::submitForm($form, $form_state);
}