You are here

public function CheeseburgerMenu::blockSubmit in Cheeseburger Menu 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::blockSubmit()
  2. 8.2 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::blockSubmit()
  3. 8.3 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::blockSubmit()

sends and store the block by collected data

Overrides BlockPluginTrait::blockSubmit

File

src/Plugin/Block/CheeseburgerMenu.php, line 419

Class

CheeseburgerMenu
Plugin annotation @Block( id = "cheesebuger_menu_block", admin_label = @Translation("Cheeseburger Menu"), category = @Translation("Block") )

Namespace

Drupal\cheeseburger_menu\Plugin\Block

Code

public function blockSubmit($form, FormStateInterface $form_state) {

  /*
    The data used to collect all the information
    that used to be to display the block
  */
  parent::blockSubmit($form, $form_state);
  $values = $form_state
    ->getValues();
  $controller = new renderCheeseburgerMenuBlock();
  $menus = $controller
    ->getAllMenuLinkId();
  $taxonomies = $controller
    ->getAllTaxonomyTermIds();
  $breakpoints = $controller
    ->returnBreakpointsForDefaultTheme();
  $taxonomiesConf = [];
  $taxonomiesWeight = [];
  $taxonomyTitles = [];

  //getting menus which will be shown
  foreach ($menus as $id) {
    if ($values['menu_fieldset'][$id . '_container'][$id . '_checkbox'] == 1) {
      $menusConf[$id] = 1;
      $menusWeight[$id] = $values['menu_fieldset'][$id . '_weight'];
      $menusTitle = $values['menu_fieldset'][$id . '_title'];
      if ($menusTitle == 0) {
        $menusTitles[$id] = FALSE;
      }
      elseif ($menusTitle == 1) {
        $menusTitles[$id] = TRUE;
      }
      elseif ($menusTitle == 2) {
        $menusTitles[$id] = $values['menu_fieldset'][$id . '_manual_title'];
      }
    }
  }

  //getting taxonomies which will be shown
  foreach ($taxonomies as $id) {
    if ($values['taxonomies'][$id . '_container'][$id . '_checkbox'] == 1) {
      $taxonomiesConf[$id] = 1;
      $taxonomiesWeight[$id] = $values['taxonomies'][$id . '_weight'];
      $taxonomyTitle = $values['taxonomies'][$id . '_title'];
      if ($taxonomyTitle == 0) {
        $taxonomyTitles[$id] = FALSE;
      }
      elseif ($taxonomyTitle == 1) {
        $taxonomyTitles[$id] = TRUE;
      }
      elseif ($taxonomyTitle == 2) {
        $taxonomyTitles[$id] = $values['taxonomies'][$id . '_manual_title'];
      }
    }
  }
  $breakpointsConf = [];
  if ($values['breakpoint_fielset_data']['all'] == 1) {
    $this->configuration['breakpoint_all'] = FALSE;
    foreach ($breakpoints as $name => $breakpoint) {
      if (strtolower($breakpoint['label']) == 'all') {
        continue;
      }
      if ($values['breakpoint_fielset_data']['breakpoint_checkbox_' . $name] == 1) {
        $help_array = [];
        $help_array['name'] = $name;
        $help_array['mediaQuery'] = $breakpoint['mediaQuery'];
        $breakpointsConf[] = $help_array;
      }
      else {
        $help_array = [];
        $help_array['name'] = FALSE;
        $help_array['mediaQuery'] = $breakpoint['mediaQuery'];
        $breakpointsConf[] = $help_array;
      }
    }
  }
  else {
    $this->configuration['breakpoint_all'] = TRUE;
  }
  $this->configuration['menus_appear'] = $menusConf;
  $this->configuration['menus_weight'] = $menusWeight;
  $this->configuration['menus_title'] = $menusTitles;
  $this->configuration['taxonomy_appear'] = $taxonomiesConf;
  $this->configuration['taxonomy_weight'] = $taxonomiesWeight;
  $this->configuration['taxonomy_title'] = $taxonomyTitles;
  if (array_key_exists('cart', $values['additional_options'])) {
    $this->configuration['cart_appear'] = $values['additional_options']['cart'];
    $this->configuration['cart_weight'] = $values['additional_options']['cart_weight'];
  }
  $this->configuration['phone_appear'] = $values['additional_options']['phone'];
  $this->configuration['phone_weight'] = $values['additional_options']['phone_weight'];
  $this->configuration['phone_store'] = $values['additional_options']['phone_store'];
  $this->configuration['phone_number'] = $values['additional_options']['phone_number'];
  $this->configuration['lang_switcher'] = isset($values['lang_switcher_checkbox']) ? $values['lang_switcher_checkbox'] : FALSE;
  $this->configuration['lang_switcher_weight'] = isset($values['language_switcher_weight']) ? $values['language_switcher_weight'] : 0;

  /*$this->configuration['collapsible_menu'] = $values['additional_options']['collapsibleMenu'];
    $this->configuration['interactive_parent'] = $values['additional_options']['interactiveParentMenu'];*/
  $this->configuration['css_default'] = $values['css_default'];
  $this->configuration['headerHeight'] = $values['headerHeight'];
  $this->configuration['headerPadding'] = $values['headerPadding'];
  $this->configuration['breakpoints'] = $breakpointsConf;
}