1 layout.module layout_get_layout_template_info($template_name = NULL, $rebuild = FALSE)

Load the information of either a single layout template or all available layout templates.

Parameters

string $template_name: Optionally specify a name of a single layout template, e.g. "boxton" or "simmons". If no layout template name is specified, information for all layout templates will be returned.

boolean $rebuild: Whether the list of layout template info needs to be rebuilt (see https://github.com/backdrop/backdrop-issues/issues/984). The rebuild is required only on specific cases, so this defaults to FALSE. That way, the rest of the times the layout cache is used (when available) for performance reasons.

Return value

array|boolean: The layout template information, as returned by either a stand-alone template .info file, or through a module's hook_layout_info().

See also

hook_layout_info()

File

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

Code

function layout_get_layout_template_info($template_name = NULL, $rebuild = FALSE) {
  $info = &backdrop_static(__FUNCTION__);

  // Try getting a cached list of layout info.
  if (!isset($info) && !$rebuild) {
    $cache = cache('cache')->get('layout_info');

    if ($cache && $cache->data) {
      $info = $cache->data;
    }
  }

  // Rebuild the list of layout info.
  if (!isset($info) || $rebuild) {
    $files = backdrop_system_listing('/^' . BACKDROP_PHP_FUNCTION_PATTERN . '\.info$/', 'layouts', 'name', 0);
    $init = array();

    foreach ($files as $name => $file) {
      $init[$name] = backdrop_parse_info_file($file->uri);

      // Skip modules or themes that have been placed in the wrong directory.
      if (isset($init[$name]['type']) && $init[$name]['type'] != 'layout') {
        unset($init[$name]);
        continue;
      }

      $init[$name]['path'] = dirname($file->uri);
      $init[$name]['title'] = $init[$name]['name'];
      $init[$name]['name'] = $name;
    }
    $info = _layout_get_all_info('layout', $init);

    // Populate defaults.
    foreach ($info as $name => $layout_info) {
      $info[$name] += array(
        'hidden' => FALSE,
        'preview' => 'preview.png',
        'default region' => 'content',
        'stylesheets' => array(
          'all' => array(str_replace('_', '-', $name) . '.css'),
        ),
      );
      if (!isset($info[$name]['template'])) {
        $template_path = BACKDROP_ROOT . '/' . $layout_info['path'] . '/layout--' . str_replace('_', '-', $name) . '.tpl.php';

        if (is_file($template_path)) {
          $info[$name]['template'] = 'layout--' . str_replace('_', '-', $name);
        }
      }
    }

    // Sort the available layouts by display name.
    backdrop_sort($info, array('title' => SORT_STRING));

    cache('cache')->set('layout_info', $info);
  }

  if ($template_name) {
    if (isset($info[$template_name])) {
      return $info[$template_name];
    }
    else {
      return FALSE;
    }
  }
  else {
    return $info;
  }
}