You are here

public function TBMegaMenuBuilder::syncConfig in The Better Mega Menu 2.x

Same name and namespace in other branches
  1. 8 src/TBMegaMenuBuilder.php \Drupal\tb_megamenu\TBMegaMenuBuilder::syncConfig()

Populate the item_config values.

Parameters

array $items: Menu items.

array $item_config: The item config array to populate.

string $section: The menu section.

Overrides TBMegaMenuBuilderInterface::syncConfig

1 call to TBMegaMenuBuilder::syncConfig()
TBMegaMenuBuilder::syncConfigAll in src/TBMegaMenuBuilder.php
Add item config values to menu config array.

File

src/TBMegaMenuBuilder.php, line 316

Class

TBMegaMenuBuilder
Defines a TBMegaMenuBuilder.

Namespace

Drupal\tb_megamenu

Code

public function syncConfig(array $items, array &$item_config, string $section) {
  if (empty($item_config['rows_content'])) {
    $item_config['rows_content'][0][0] = [
      'col_content' => [],
      'col_config' => [],
    ];

    // Add menu items to the configuration.
    self::addColContent($items, $item_config);

    // If the item in the first posision is empty, unset it.
    if (empty($item_config['rows_content'][0][0]['col_content'])) {
      unset($item_config['rows_content'][0]);
    }
  }
  else {
    $hash = [];
    foreach ($item_config['rows_content'] as $row_delta => $row) {
      foreach ($row as $col_delta => $col) {
        foreach ($col['col_content'] as $item_delta => $tb_item) {
          if (!empty($tb_item) && is_array($tb_item)) {

            // Add a menu item to the config.
            if ($tb_item['type'] == 'menu_item') {
              self::syncMenuItem($hash, $tb_item, $row_delta, $col_delta, $item_delta, $items, $item_config);
            }
            elseif ($tb_item['type'] == 'block' && !empty($tb_item['block_id'])) {
              self::syncBlock($tb_item, $row_delta, $col_delta, $item_delta, $section, $item_config);
            }
            else {
              self::removeColumn($tb_item, $row_delta, $col_delta, $item_delta, $item_config);
            }
          }
        }
      }
    }

    // Add all enabled links to the configuration.
    self::insertEnabledLinks($items, $hash, $item_config);
  }
}