You are here

public function TabFormBase::submitForm in Block Tabs 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 FormInterface::submitForm

File

src/Form/TabFormBase.php, line 121

Class

TabFormBase
Provides a base form for tab.

Namespace

Drupal\blocktabs\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $form_state
    ->cleanValues();

  // The tab configuration is stored in the 'data' key in the form,
  // pass that through for submission.
  $tab_data = (new FormState())
    ->setValues($form_state
    ->getValue('data'));
  $this->tab
    ->submitConfigurationForm($form, $tab_data);

  // $logger = \Drupal::logger('blocktabs');
  // $logger->notice('submitForm:' . var_export($tab_data, true));
  // $logger->notice('default_view_name:' . var_export($default_view_name, true));
  // Update the original form values.
  $form_state
    ->setValue('data', $tab_data
    ->getValues());
  $this->tab
    ->setTitle($form_state
    ->getValue('title'));
  $this->tab
    ->setWeight($form_state
    ->getValue('weight'));
  if (!$this->tab
    ->getUuid()) {
    $this->blocktabs
      ->addTab($this->tab
      ->getConfiguration());
  }
  else {
    $uuid = $this->tab
      ->getUuid();
    $config = $this->tab
      ->getConfiguration();
    $this->blocktabs
      ->getTabs()
      ->setInstanceConfiguration($uuid, $config);
  }

  // $config = $this->tab->getConfiguration();
  // $logger = \Drupal::logger('blocktabs');
  // $logger->notice('$config:' . var_export($config, true));
  // $tab = $this->blocktabs->getTab($this->tab->getUuid());
  // $config1 = $tab->getConfiguration();
  // $logger = \Drupal::logger('blocktabs');
  // $logger->notice('$config:' . var_export($config1, true));
  // $tab = $this->tab;
  $this->blocktabs
    ->save();
  \Drupal::messenger()
    ->addMessage($this
    ->t('The tab was successfully applied.'));
  $form_state
    ->setRedirectUrl($this->blocktabs
    ->toUrl('edit-form'));
}