You are here

public function UltimenuSettingsForm::submitForm in Ultimenu 8

Implements \Drupal\Core\Form\FormInterface::submitForm().

Overrides ConfigFormBase::submitForm

File

src/UltimenuSettingsForm.php, line 200

Class

UltimenuSettingsForm
Defines ultimenu admin settings form.

Namespace

Drupal\ultimenu

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $data = [];

  // Do not litter the ultimenu.settings.yml.
  $data['blocks'] = array_filter($form_state
    ->getValue('blocks'));
  $data['regions'] = array_filter($form_state
    ->getValue('regions'));
  $data['goodies'] = array_filter($form_state
    ->getValue('goodies'));
  $data['skins'] = $form_state
    ->getValue('skins');
  $config = $this->configFactory
    ->getEditable('ultimenu.settings');
  if ($form_state
    ->hasValue('blocks')) {
    $config
      ->set('blocks', $data['blocks']);
  }
  if ($form_state
    ->hasValue('regions')) {
    $config
      ->set('regions', $data['regions']);
  }
  if ($form_state
    ->hasValue('goodies')) {
    $config
      ->set('goodies', $data['goodies']);
  }
  if ($form_state
    ->hasValue('skins')) {
    $config
      ->set('skins', $data['skins']);
  }
  $config
    ->save();

  // Reset static and theme info to get the new blocks and regions fetched.
  $this->ultimenuManager
    ->clearCachedDefinitions();

  // Invalidate the block cache to update ultimenu-based derivatives.
  if ($this->ultimenuManager
    ->getModuleHandler()
    ->moduleExists('block')) {
    \Drupal::service('plugin.manager.block')
      ->clearCachedDefinitions();
  }

  // If anything fails, notice to clear the cache.
  drupal_set_message($this
    ->t('Be sure to <a href=":clear_cache">clear the cache</a> <strong>ONLY IF</strong> trouble to see the updated regions at <a href=":block_admin">block admin</a>.', array(
    ':clear_cache' => Url::fromRoute('system.performance_settings')
      ->toString(),
    ':block_admin' => Url::fromRoute('block.admin_display')
      ->toString(),
  )));
  parent::submitForm($form, $form_state);
}