You are here

public function ResponsiveWrappersSettings::submitForm in Responsive wrappers 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/ResponsiveWrappersSettings.php \Drupal\responsivewrappers\Form\ResponsiveWrappersSettings::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/ResponsiveWrappersSettings.php, line 93

Class

ResponsiveWrappersSettings
Configure Responsive wrappers settings.

Namespace

Drupal\responsivewrappers\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $version = (int) $form_state
    ->getValue('version');

  // Bootstrap image classes.
  if (3 === $version) {
    $image_class = 'img-responsive';
  }
  elseif (4 === $version || 5 === $version) {
    $image_class = 'img-fluid';
  }
  else {
    $image_class = trim($form_state
      ->getValue('image_class'));
  }

  // Bootstrap iframe classes.
  if ($version > 0) {
    $iframe_wrapper_class = 'embed-responsive embed-responsive-16by9';
    $iframe_class = 'embed-responsive-item';
  }
  else {
    $iframe_wrapper_class = trim($form_state
      ->getValue('iframe_wrapper_class'));
    $iframe_class = trim($form_state
      ->getValue('iframe_class'));
  }

  // Bootstrap table classes.
  if ($version > 0) {
    $table_wrapper_class = 'table-responsive';
    $table_class = 'table';
  }
  else {
    $table_wrapper_class = trim($form_state
      ->getValue('table_wrapper_class'));
    $table_class = trim($form_state
      ->getValue('table_class'));
  }
  $config = $this
    ->config('responsivewrappers.settings');
  $config
    ->set('add_css', $form_state
    ->getValue('add_css'))
    ->set('version', $version)
    ->set('image_class', $image_class)
    ->set('iframe_wrapper_class', $iframe_wrapper_class)
    ->set('iframe_class', $iframe_class)
    ->set('table_wrapper_class', $table_wrapper_class)
    ->set('table_class', $table_class)
    ->save();
  parent::submitForm($form, $form_state);
}