You are here

public function AdminSettingsForm::submitForm in Entity Reference Hierarchy 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/AdminSettingsForm.php, line 90
Contains \Drupal\entity_hierarchy\Form\AdminSettingsForm.

Class

AdminSettingsForm
Defines a form for Entity Hierarchy Admin settings.

Namespace

Drupal\entity_hierarchy\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $config = $this
    ->config('entity_hierarchy.settings');
  foreach ($this->node_types as $key => $type) {
    $config
      ->set('nh_allowchild_' . $key, $values['nh_allowchild_' . $key]);

    //      $config->set('nh_createmenu_'.$key, $values['nh_createmenu_'.$key]);
    //      $config->set('nh_multiple_'.$key, $values['nh_multiple_'.$key]);
    $config
      ->set('nh_defaultparent_' . $key, $values['nh_defaultparent_' . $key]);

    //      $config->set('entity_hierarchy_default_menu_name', $values['entity_hierarchy_default_menu_name']);
    //      $config->set('entity_hierarchy_menu_module_edit', $values['entity_hierarchy_menu_module_edit']);
  }
  $config
    ->save();

  // Would have preferred to handle this in the entity_hierarchy_views module, but not sure how
  // Perhaps can override this form?
  if (\Drupal::moduleHandler()
    ->moduleExists('entity_hierarchy_views')) {
    $views_config = $this
      ->config('entity_hierarchy.settings');
    foreach ($this->node_types as $key => $type) {
      $views_config
        ->set('nh_default_children_view_' . $key, $values['nh_default_children_view_' . $key]);
    }
    $views_config
      ->save();
  }
  parent::submitForm($form, $form_state);
}