You are here

public function SettingsForm::submitForm in Forward 8

Same name and namespace in other branches
  1. 8.3 src/Form/SettingsForm.php \Drupal\forward\Form\SettingsForm::submitForm()
  2. 8.2 src/Form/SettingsForm.php \Drupal\forward\Form\SettingsForm::submitForm()
  3. 4.x src/Form/SettingsForm.php \Drupal\forward\Form\SettingsForm::submitForm()
  4. 4.0.x src/Form/SettingsForm.php \Drupal\forward\Form\SettingsForm::submitForm()

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/SettingsForm.php, line 430

Class

SettingsForm
Configure settings for this module.

Namespace

Drupal\forward\Form

Code

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

  // Save entity types and bundles
  $values = $form_state
    ->getValue('forward_entity_types');
  $values['node'] = TRUE;
  $entity_types = $this->entityTypeManager
    ->getDefinitions();
  foreach ($entity_types as $type => $info) {
    if (is_a($info, 'Drupal\\Core\\Entity\\ContentEntityType')) {
      if (!empty($values[$type])) {
        $this
          ->config('forward.settings')
          ->set('forward_entity_' . $type, TRUE);
      }
      else {
        $this
          ->config('forward.settings')
          ->set('forward_entity_' . $type, FALSE);
      }
      $bundles = $this->bundleInfoManager
        ->getBundleInfo($type);
      foreach ($bundles as $bundle => $bundle_info) {
        $bundle_values = $form_state
          ->getValue('forward_' . $type . '_types');
        if (!empty($values[$type]) && !empty($bundle_values[$bundle])) {
          $this
            ->config('forward.settings')
            ->set('forward_' . $type . '_' . $bundle, TRUE);
        }
        else {
          $this
            ->config('forward.settings')
            ->set('forward_' . $type . '_' . $bundle, FALSE);
        }

        // If only one bundle, it gets the same setting as its type
        if (count($bundles) == 1) {
          $this
            ->config('forward.settings')
            ->set('forward_' . $type . '_' . $bundle, $this
            ->config('forward.settings')
            ->get('forward_entity_' . $type));
        }
      }
    }
  }

  // Save view modes
  $modes = array(
    'full',
    'teaser',
  );
  $values = $form_state
    ->getValue('forward_view_modes');
  foreach ($modes as $mode) {
    if (!empty($values[$mode])) {
      $this
        ->config('forward.settings')
        ->set('forward_view_' . $mode, TRUE);
    }
    else {
      $this
        ->config('forward.settings')
        ->set('forward_view_' . $mode, FALSE);
    }
  }

  // Save all other settings
  $this
    ->config('forward.settings')
    ->set('forward_interface_type', $form_state
    ->getValue('forward_interface_type'))
    ->set('forward_interface_title', $form_state
    ->getValue('forward_interface_title'))
    ->set('forward_interface_weight', $form_state
    ->getValue('forward_interface_weight'))
    ->set('forward_link_inline', $form_state
    ->getValue('forward_link_inline'))
    ->set('forward_link_title', $form_state
    ->getValue('forward_link_title'))
    ->set('forward_link_style', $form_state
    ->getValue('forward_link_style'))
    ->set('forward_link_icon', $form_state
    ->getValue('forward_link_icon'))
    ->set('forward_link_noindex', $form_state
    ->getValue('forward_link_noindex'))
    ->set('forward_link_nofollow', $form_state
    ->getValue('forward_link_nofollow'))
    ->set('forward_form_instructions', $form_state
    ->getValue('forward_form_instructions'))
    ->set('forward_form_display_page', $form_state
    ->getValue('forward_form_display_page'))
    ->set('forward_form_display_subject', $form_state
    ->getValue('forward_form_display_subject'))
    ->set('forward_form_display_body', $form_state
    ->getValue('forward_form_display_body'))
    ->set('forward_form_confirmation', $form_state
    ->getValue('forward_form_confirmation'))
    ->set('forward_personal_message', $form_state
    ->getValue('forward_personal_message'))
    ->set('forward_personal_message_filter', $form_state
    ->getValue('forward_personal_message_filter'))
    ->set('forward_personal_message_tags', $form_state
    ->getValue('forward_personal_message_tags'))
    ->set('forward_email_logo', $form_state
    ->getValue('forward_email_logo'))
    ->set('forward_email_from_address', $form_state
    ->getValue('forward_email_from_address'))
    ->set('forward_email_subject', $form_state
    ->getValue('forward_email_subject'))
    ->set('forward_email_message', $form_state
    ->getValue('forward_email_message'))
    ->set('forward_filter_format', $form_state
    ->getValue('forward_filter_format'))
    ->set('forward_bypass_access_control', $form_state
    ->getValue('forward_bypass_access_control'))
    ->set('forward_flood_control_limit', $form_state
    ->getValue('forward_flood_control_limit'))
    ->set('forward_flood_control_error', $form_state
    ->getValue('forward_flood_control_error'))
    ->save();
  parent::submitForm($form, $form_state);
}