public static function WeMegaMenuBuilder::compareItem in Drupal Mega Menu 8.x
Same name and namespace in other branches
- 8 src/WeMegaMenuBuilder.php \Drupal\we_megamenu\WeMegaMenuBuilder::compareItem()
1 call to WeMegaMenuBuilder::compareItem()
File
- src/
WeMegaMenuBuilder.php, line 844
Class
Namespace
Drupal\we_megamenuCode
public static function compareItem($item, $level, &$menu_config, &$megamenu_config) {
$menu_sub_count = count($item['subtree']);
$derivativeId = $item['derivativeId'];
$megamenu_sub_count = self::countMegamenuSubItem($menu_config, $derivativeId);
if (!isset($menu_config[$derivativeId])) {
$new_item = self::createNewMegamenuItem($level, $derivativeId, $item);
$megamenu_config->menu_config->{$derivativeId} = $new_item;
$menu_config[$derivativeId] = json_decode(json_encode($new_item), TRUE);
}
if ($menu_sub_count == $megamenu_sub_count) {
$menu_ids = self::getMenuSubIds($item);
$megamenu_ids = self::getMegamenuSubIds($menu_config[$derivativeId]);
if (!self::equalArrays($menu_ids, $megamenu_ids)) {
$megamenu_item = $menu_config[$derivativeId];
$pos_item = 0;
foreach ($megamenu_item['rows_content'] as $i => $cols) {
foreach ($cols as $j => $col) {
$col_content = isset($col['col_content']) ? $col['col_content'] : [];
foreach ($col_content as $k => $sub_item) {
if ($sub_item['type'] == 'we-mega-menu-li') {
$menu_item = $item['subtree'][$pos_item];
$megamenu_mlid = $sub_item['mlid'];
$menu_id = $menu_item['derivativeId'];
if ($megamenu_mlid != $menu_id) {
$new_megamenu_item = self::createNewMegamenuCellItem($menu_item, $menu_id);
if (!isset($menu_config[$derivativeId]['rows_content'][$i][$j]['col_config'])) {
$new_col_config = self::createNewMegamenuColConfig();
$megamenu_config->menu_config->{$derivativeId}->rows_content[$i][$j]->col_config = $new_col_config;
$menu_config[$derivativeId]['rows_content'][$i][$j]['col_config'] = json_decode(json_encode($new_col_config), TRUE);
}
$megamenu_config->menu_config->{$derivativeId}->rows_content[$i][$j]->col_content[$k] = $new_megamenu_item;
$menu_config[$derivativeId]['rows_content'][$i][$j]['col_content'][$k] = json_decode(json_encode($new_megamenu_item), TRUE);
}
$pos_item++;
}
}
}
}
}
}
else {
$megamenu_item = $menu_config[$derivativeId];
$pos_item = 0;
$ii = -1;
$jj = -1;
$i = -1;
$j = -1;
foreach ($megamenu_item['rows_content'] as $i => $row) {
foreach ($row as $j => $col) {
$col_content = isset($col['col_content']) ? $col['col_content'] : [];
foreach ($col_content as $k => $sub_item) {
if ($sub_item['type'] == 'we-mega-menu-li') {
$ii = $i;
$jj = $j;
if ($pos_item < $menu_sub_count) {
$menu_item = $item['subtree'][$pos_item];
$megamenu_mlid = $sub_item['mlid'];
$menu_id = $menu_item['derivativeId'];
if ($megamenu_mlid != $menu_id) {
if (!isset($menu_config[$derivativeId]['rows_content'][$i][$j]['col_config'])) {
$new_col_config = self::createNewMegamenuColConfig();
$megamenu_config->menu_config->{$derivativeId}->rows_content[$i][$j]->col_config = $new_col_config;
$menu_config[$derivativeId]['rows_content'][$i][$j]['col_config'] = json_decode(json_encode($new_col_config), TRUE);
}
$new_megamenu_item = self::createNewMegamenuCellItem($menu_item, $menu_id);
$megamenu_config->menu_config->{$derivativeId}->rows_content[$i][$j]->col_content[$k] = $new_megamenu_item;
$menu_config[$derivativeId]['rows_content'][$i][$j]['col_content'][$k] = json_decode(json_encode($new_megamenu_item), TRUE);
}
}
else {
$col_content = $megamenu_config->menu_config->{$derivativeId}->rows_content[$i][$j]->col_content;
unset($col_content[$k]);
$megamenu_config->menu_config->{$derivativeId}->rows_content[$i][$j]->col_content = $col_content;
$menu_config[$derivativeId]['rows_content'][$i][$j]['col_content'] = json_decode(json_encode($col_content), TRUE);
}
$pos_item++;
}
}
}
}
if ($ii == -1) {
$i++;
$ii = $i;
$jj = $j = 0;
if (!isset($menu_config[$derivativeId]['rows_content'][$ii][$jj])) {
$megamenu_config->menu_config->{$derivativeId}->rows_content[$ii][$jj] = new \stdClass();
$menu_config[$derivativeId]['rows_content'][$ii][$jj] = [];
}
}
for ($l = $pos_item; $l < $menu_sub_count; $l++) {
$menu_item = $item['subtree'][$l];
$menu_id = $menu_item['derivativeId'];
$new_megamenu_item = self::createNewMegamenuCellItem($menu_item, $menu_id);
if (!isset($menu_config[$derivativeId]['rows_content'][$ii][$jj]['col_config'])) {
$new_col_config = self::createNewMegamenuColConfig();
$megamenu_config->menu_config->{$derivativeId}->rows_content[$ii][$jj]->col_config = $new_col_config;
$menu_config[$derivativeId]['rows_content'][$ii][$jj]['col_config'] = json_decode(json_encode($new_col_config), TRUE);
}
$megamenu_config->menu_config->{$derivativeId}->rows_content[$ii][$jj]->col_content[] = $new_megamenu_item;
$menu_config[$derivativeId]['rows_content'][$ii][$jj]['col_content'][] = json_decode(json_encode($new_megamenu_item), TRUE);
}
}
}