You are here

function tb_megamenu_features_rebuild in The Better Mega Menu 7

Implements hook_features_rebuild().

1 call to tb_megamenu_features_rebuild()
tb_megamenu_features_revert in ./tb_megamenu.features.inc
Implements hook_features_revert().

File

./tb_megamenu.features.inc, line 94
Features related functions.

Code

function tb_megamenu_features_rebuild($module) {

  // Workaround to make sure that the feature module's file containing the
  // export function is loaded. When drush feature-revert is run with the
  // --force argument, the file is not loaded (for whatever reason), so the
  // export function does not exist and $tb_megamenus below is null. Why does
  // this happen?
  module_load_include('inc', $module, $module . '.' . 'features.tb_megamenu');
  $tb_megamenus = module_invoke($module, 'tb_megamenu_default_menus');
  foreach ($tb_megamenus as $menu_name => $tb_megamenu) {
    $menu_config = $tb_megamenu['menu_config'];
    $new_config = array();

    // Get the menu name
    $menu_details = explode('|', $menu_name);
    $menu_name_id = $menu_details[0];

    // Loop all menu items to recursively convert item identifiers back to
    // mlids.
    foreach ($menu_config as $config) {
      $mlid = tb_megamenu_export_identifier_to_mlid($config['identifier'], $menu_name_id);
      $new_config[$mlid] = $config;
      tb_megamenu_export_convert_identifiers($new_config[$mlid], $menu_name_id);
    }
    $tb_megamenu['menu_config'] = json_encode($new_config);
    $tb_megamenu['block_config'] = json_encode($tb_megamenu['block_config']);

    // Create a new record for the current menu or overwrite an existing one.
    db_merge('tb_megamenus')
      ->key(array(
      'menu_name' => $tb_megamenu['menu_name'],
      'language' => $tb_megamenu['language'],
    ))
      ->fields(array(
      'menu_config' => $tb_megamenu['menu_config'],
      'block_config' => $tb_megamenu['block_config'],
    ))
      ->execute();
  }
}