public function TBMegaMenuBuilder::insertTbMenuItem in The Better Mega Menu 8
Same name and namespace in other branches
- 2.x src/TBMegaMenuBuilder.php \Drupal\tb_megamenu\TBMegaMenuBuilder::insertTbMenuItem()
Insert a menu item into the item config array.
Parameters
array $item_config: The item config array.
int|string $row: The row to insert at.
int|string $col: The column to insert at.
object $item: The menu item to insert.
Overrides TBMegaMenuBuilderInterface::insertTbMenuItem
1 call to TBMegaMenuBuilder::insertTbMenuItem()
- TBMegaMenuBuilder::insertEnabledLinks in src/
TBMegaMenuBuilder.php - Insert an enabled link into the TB config.
File
- src/
TBMegaMenuBuilder.php, line 514
Class
- TBMegaMenuBuilder
- Defines a TBMegaMenuBuilder.
Namespace
Drupal\tb_megamenuCode
public function insertTbMenuItem(array &$item_config, $row, $col, $item) {
$idx = 0;
$col_content = isset($item_config['rows_content'][$row][$col]['col_content']) ? array_values($item_config['rows_content'][$row][$col]['col_content']) : [];
current($col_content);
foreach ($col_content as $value) {
if (!empty($value['weight']) && $value['weight'] < $item->link
->getWeight()) {
next($col_content);
$idx = key($col_content);
}
}
for ($col = count($col_content); $col > $idx; $col--) {
$col_content[$col] = $col_content[$col - 1];
}
$col_content[$idx] = [
'plugin_id' => $item->link
->getPluginId(),
'type' => 'menu_item',
'weight' => $item->link
->getWeight(),
'tb_item_config' => [],
];
$item_config['rows_content'][$row][$col]['col_content'] = $col_content;
}