You are here

public function VisibilityConfigurationForm::submitForm in Vertical Tabs Config 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/VisibilityConfigurationForm.php, line 139

Class

VisibilityConfigurationForm
Configure visibility for this site.

Namespace

Drupal\vertical_tabs_config\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $config = [];
  $roles = user_roles();
  $ct_list = NodeType::loadMultiple();
  $vertical_tabs = vertical_tabs_config_vertical_tab_list();
  foreach ($ct_list as $ct_machine_name => $obj) {
    $selected_roles = [];
    foreach ($roles as $rid => $value) {
      if ($values['role_' . $ct_machine_name . '_' . $rid] == 1) {
        $selected_roles[] = $rid;
      }
    }
    foreach ($vertical_tabs as $vt_machine_name => $vt_human_name) {
      $data = [
        'vertical_tab' => $vt_machine_name,
        'content_type' => $ct_machine_name,
        'hidden' => $values['hide_' . $ct_machine_name . '_' . $vt_machine_name],
        'roles' => json_encode($selected_roles),
      ];
      $config[] = $data;
    }
  }
  $this
    ->verticalTabsConfigSaveConfig($config);
  parent::submitForm($form, $form_state);
}