You are here

public static function WeMegaMenuBuilder::menuItemInsert in Drupal Mega Menu 8.x

Same name and namespace in other branches
  1. 8 src/WeMegaMenuBuilder.php \Drupal\we_megamenu\WeMegaMenuBuilder::menuItemInsert()

Insert new menu item.

Parameters

string $key_menu: Public static function menuItemInsert key_menu.

object $menu_config: Public static function menuItemInsert menu_config.

object $menu_item: Public static function menuItemInsert menu_item.

object $menu_child_item: Public static function menuItemInsert menu_child_item.

1 call to WeMegaMenuBuilder::menuItemInsert()
we_megamenu_entity_insert in ./we_megamenu.module
Implements hook_entity_insert().

File

src/WeMegaMenuBuilder.php, line 351

Class

WeMegaMenuBuilder

Namespace

Drupal\we_megamenu

Code

public static function menuItemInsert($key_menu, $menu_config, $menu_item, $menu_child_item) {
  if (isset($menu_child_item['col_content']) && isset($menu_child_item['col_cfg'])) {
    $tmp_col_content = $menu_child_item['col_content'];
    $tmp_col_cfg = $menu_child_item['col_cfg'];
    if (isset($menu_item->rows_content)) {
      $row_count = 0;
      $col_count = 0;
      if (count($menu_item->rows_content)) {
        $li_flag = FALSE;
        $rows_content = $menu_item->rows_content;
        foreach ($rows_content as $key_rows => $rows) {
          if (is_array($rows)) {
            foreach ($rows as $key_row_col => $row) {
              if (isset($row->col_content)) {
                $cols = $row->col_content;
                if (is_array($cols)) {
                  foreach ($cols as $key_col => $col) {
                    if (isset($col->mlid)) {
                      $row_count = $key_rows;
                      $col_count = $key_row_col;
                      $li_flag = TRUE;
                    }
                  }
                }
              }
            }
          }
        }
        if (!$li_flag) {
          $bk_items = $menu_config->menu_config->{$key_menu}->rows_content;
          $menu_config->menu_config->{$key_menu}->rows_content = [];
          $menu_config->menu_config->{$key_menu}->rows_content[0] = [];
          foreach ($bk_items as $key => $value) {
            $menu_config->menu_config->{$key_menu}->rows_content[] = $value;
          }
        }
      }
      $menu_config->menu_config->{$key_menu}->rows_content[$row_count][$col_count]->col_content[] = $tmp_col_content;
      $items_validate_serialize = array_map("serialize", $menu_config->menu_config->{$key_menu}->rows_content[$row_count][$col_count]->col_content);
      $items_validate_unique = array_unique($items_validate_serialize);
      $items_validate = array_map("unserialize", $items_validate_unique);
      $menu_config->menu_config->{$key_menu}->rows_content[$row_count][$col_count]->col_content = $items_validate;
      if (!isset($menu_config->menu_config->{$key_menu}->rows_content[$row_count][$col_count]->col_config)) {
        $menu_config->menu_config->{$key_menu}->rows_content[$row_count][$col_count]->col_config = $tmp_col_cfg;
      }
    }
  }
}