You are here

public function MmenuSettingsForm::submitForm in Mobile sliding menu 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/MmenuSettingsForm.php, line 202

Class

MmenuSettingsForm
Class MmenuSettingsForm.

Namespace

Drupal\mmenu\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  switch ($values['op']
    ->__toString()) {
    case t('Save'):

      //        $blocks = array();
      //
      //        // Updates the blocks.
      //        foreach ($values['blocks'] as $k => $block) {
      //          if (!empty($block['module_delta'])) {
      //            list($module, , $id) = explode('|', $block['module_delta']);
      //            $blocks[$k] = $block;
      //            $blocks[$k] += array(
      //              'module' => $module,
      //              'delta' => $id,
      //            );
      //          }
      //        }
      $mmenu = array(
        'enabled' => $values['general']['enabled'],
        'name' => $values['general']['name'],
        'blocks' => $values['blocks'],
        'options' => Yaml::decode($values['mmenu_options']['yaml']),
        'configurations' => Yaml::decode($values['mmenu_configurations']['yaml']),
      );
      $config = \Drupal::configFactory()
        ->getEditable('mmenu.settings');
      $config
        ->set('mmenu_item_' . $values['general']['name'], $mmenu);
      $config
        ->save();

      // Clears mmenus cache.
      \Drupal::cache()
        ->delete('mmenus:cache');
      drupal_set_message(t('The settings have been saved.'));
      break;
    case t('Reset'):

      // Deletes the mmenu settings from database.
      $config = \Drupal::configFactory()
        ->getEditable('mmenu.settings');
      $config
        ->delete('mmenu_item_' . $values['general']['name']);

      // Clears mmenus cache.
      \Drupal::cache()
        ->delete('mmenus:cache');
      drupal_set_message(t('The settings have been reset.'));
      break;
  }
}