You are here

public function CheeseburgerMenuBlock::submitConfigurationForm in Cheeseburger Menu 5.0.x

Most block plugins should not override this method. To add submission handling for a specific block type, override BlockBase::blockSubmit().

Overrides BlockPluginTrait::submitConfigurationForm

See also

\Drupal\Core\Block\BlockBase::blockSubmit()

File

src/Plugin/Block/CheeseburgerMenuBlock.php, line 328

Class

CheeseburgerMenuBlock
Provides a 'CheeseburgerMenu' block.

Namespace

Drupal\cheeseburger_menu\Plugin\Block

Code

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

  // Single config.
  $this
    ->setConfigurationValue('default_css', $form_state
    ->getValue('default_css'));
  $this
    ->setConfigurationValue('default_js', $form_state
    ->getValue('default_js'));
  $this
    ->setConfigurationValue('hidden', $form_state
    ->getValue('hidden'));
  $this
    ->setConfigurationValue('parent_menu_as_link', $form_state
    ->getValue('parent_menu_as_link'));
  $this
    ->setConfigurationValue('show_navigation', $form_state
    ->getValue('show_navigation'));
  $this
    ->setConfigurationValue('invoke_hooks', $form_state
    ->getValue('invoke_hooks'));
  foreach ($form_state
    ->getValue([
    'colors',
    'row',
  ]) as $color_settings_values) {
    foreach ($color_settings_values as $color_setting_name => $color_setting_value) {
      $this
        ->setConfigurationValue($color_setting_name, $color_setting_value);
    }
  }

  // Config group.
  $menus = [];
  foreach ($form_state
    ->getValue('menus') as $key => $menu) {
    if ($menu['menu_type'] === 'enabled') {
      continue;
    }
    if ($menu['menu_type'] === 'hidden') {
      break;
    }
    if (!empty($menu['settings']['show_links_in_navigation'])) {
      $menu['settings']['max_depth'] = 1;
      $menu['settings']['default_expanded'] = FALSE;
    }

    // Setting icon.
    $icon_setting =& $menu['settings']['icon'];
    if (isset($icon_setting[0])) {

      /** @var \Drupal\file\Entity\File $file */
      $file = $this->entityTypeManager
        ->getStorage('file')
        ->load($icon_setting[0]);
      $icon_setting = file_get_contents($file
        ->getFileUri());
    }
    else {
      $menu_settings = $this
        ->getConfigValue('menus', []);
      $icon_setting = $menu_settings[$key]['settings']['icon'] ?? '';
    }
    $menus[$key] = $menu;
  }
  uasort($menus, function ($menu1, $menu2) {
    return $menu1['weight'] <=> $menu2['weight'];
  });
  foreach ($menus as $key => &$menu) {
    $menu['id'] = $key;
  }
  $this
    ->setConfigurationValue('menus', $menus);
  parent::submitConfigurationForm($form, $form_state);
}