You are here

public function TaxoAdminForm::submitForm in Taxonomy Facets 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/TaxoAdminForm.php, line 107
Contains Drupal\taxonomy_facets\Form\TaxoAdminForm.

Class

TaxoAdminForm

Namespace

Drupal\taxonomy_facets\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Retrieve the configuration
  $config = \Drupal::configFactory()
    ->getEditable('taxonomy_facets.settings');
  $config
    ->set('page_title', $form_state
    ->getValue('page_title'));
  $config
    ->set('show_nodes_if_no_filters', $form_state
    ->getValue('show_nodes_if_no_filters'));
  $config
    ->set('number_of_nodes_per_page', $form_state
    ->getValue('number_of_nodes_per_page'));

  // Deal with vocabularies
  $vocabularies = \Drupal\taxonomy\Entity\Vocabulary::loadMultiple();
  foreach ($vocabularies as $vocabulary) {
    $config
      ->set($vocabulary
      ->id(), $form_state
      ->getValue($vocabulary
      ->id()));
  }

  // Deal with content types
  $contentTypes = \Drupal::service('entity.manager')
    ->getStorage('node_type')
    ->loadMultiple();
  foreach ($contentTypes as $contentType) {
    $config
      ->set('ct_' . $contentType
      ->id(), $form_state
      ->getValue('ct_' . $contentType
      ->id()));
  }
  $config
    ->save();
  parent::submitForm($form, $form_state);
}