1 layout.module layout_load_multiple($layout_names, $skip_menu_items = FALSE)

Load multiple layouts based on a particular criteria.

Parameters

array $layout_names: The names of the layouts to be loaded.

bool $skip_menu_items: Flag to skip the attempted loading of menu items for the loaded layouts. This should be set to TRUE if loading layouts that definitely do not have menu items associated with them, for example the default layouts or a layout that overrides an existing menu path.

Return value

Layout[]: An array of Layout object instances.

File

core/modules/layout/layout.module, line 1162
The Layout module creates pages and wraps existing pages in layouts.

Code

function layout_load_multiple($layout_names, $skip_menu_items = FALSE) {
  $loaded_layouts = &backdrop_static(__FUNCTION__, array());

  $layouts_to_load = array();
  foreach ($layout_names as $layout_name) {
    if (!isset($loaded_layouts[$layout_name])) {
      $layouts_to_load[] = $layout_name;
    }
  }

  if ($layouts_to_load) {
    $menu_items = layout_menu_item_load_multiple($layout_names);

    // Cache the raw config files once read.
    $configs = layout_get_all_configs('layout');

    // Create the layout instances and associate the menu items with each.
    foreach ($layouts_to_load as $layout_name) {
      if (isset($configs[$layout_name])) {
        $layout_data = $configs[$layout_name];
        $loaded_layouts[$layout_name] = new Layout($layout_data);

        // Associate the applicable menu item.
        if (isset($layout_data['path']) && !$skip_menu_items) {
          // Most of the time, layouts will be loaded as a group, including the
          // layout that owns the menu item.
          if (isset($menu_items[$layout_data['path']])) {
            $loaded_layouts[$layout_name]->menu_item = $menu_items[$layout_data['path']];
          }
          // In the situation that a layout is loaded separately of its menu
          // item owner, load the menu item by path.
          elseif ($menu_item = layout_menu_item_load_multiple_by_path($layout_data['path'])) {
            $loaded_layouts[$layout_name]->menu_item = $menu_item;
          }
        }
      }
    }
  }

  // Return the requested layouts.
  $layouts = array();

  foreach ($layout_names as $layout_name) {
    if (isset($loaded_layouts[$layout_name])) {
      $layouts[$layout_name] = $loaded_layouts[$layout_name];
    }
    else {
      $layouts[$layout_name] = FALSE;
    }
  }

  return $layouts;
}