You are here

function tb_megamenu_features_export_render in The Better Mega Menu 7

Implements hook_features_export_render().

File

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

Code

function tb_megamenu_features_export_render($module, $data) {
  $menus = array();
  foreach ($data as $menu_name) {
    $menu_details = explode('|', $menu_name);
    $menu_name_id = $menu_details[0];
    $menu_language = $menu_details[1];

    // Query the configuration of the current menu.
    $menu = db_select('tb_megamenus', 'tb')
      ->fields('tb')
      ->condition('menu_name', $menu_name_id)
      ->condition('language', $menu_language)
      ->execute()
      ->fetchObject();
    if ($menu) {
      $menu_config = json_decode($menu->menu_config, TRUE);

      // Loop all menu items and convert mlid's to identifiers recursively.
      $new_config = array();
      foreach ($menu_config as $mlid => $config) {
        tb_megamenu_export_convert_mlids($config, $mlid);
        $new_config[] = $config;
      }
      $menu->menu_config = $new_config;
      $menu->block_config = json_decode($menu->block_config, TRUE);
      $menus[$menu_name] = $menu;
    }
  }

  // Render the PHP code for the "default hook" function configured in
  // hook_features_api() and created in the MODULENAME.features.tb_megamenu.inc
  // file.
  $code = "  return " . features_var_export($menus, '  ') . ";";

  // Key the code by the "default hook".
  return array(
    'tb_megamenu_default_menus' => $code,
  );
}