1.20.x layout.theme.inc layout_preprocess_layout(&$variables)

Prepares variables for layout templates.

This uses [module_name]_preprocess_layout() instead of template_preprocess_layout() so that it can run last. Layout module is given a weight of 60 in hook_install(), so it should run last compared to other modules.

File

modules/layout/layout.theme.inc, line 284
Theme functions for the Layout module.

Code

function layout_preprocess_layout(&$variables) {
  $settings = $variables['layout']->settings;

  // Check if any Title Component blocks have been placed. These will override
  // the variables here.
  $block_exists = _layout_page_component_blocks_exist($variables);

  $variables += array(
    'action_links' => NULL,
    'tabs' => NULL,
    'messages' => NULL,
    'title' => NULL,
  );

  if (!$variables['admin']) {
    if (!isset($variables['title']) && !$block_exists['title']) {
      if ($settings['title_display'] === LAYOUT_TITLE_NONE) {
        $variables['title'] = NULL;
      }
      else {
        $variables['title'] = backdrop_get_title();
      }
    }

    // Generate messages last in order to capture as many as possible for the
    // current page.
    if (!isset($variables['messages']) && !$block_exists['messages']) {
      $variables['messages'] = theme('status_messages');
    }
  }
  else {
    $variables['title'] = isset($variables['content']['title']) ? $variables['content']['title'] : '';
  }

  if (!$variables['admin']) {
    if (!$block_exists['action_links']) {
      $variables['action_links'] = menu_local_actions();
    }
    if (!$block_exists['tabs']) {
      $variables['tabs'] = menu_local_tabs();
    }
  }

  // Build HTML for displaying flexible templates.
  if (isset($variables['layout_info']['template']) && ($variables['layout_info']['template'] == 'layout--flexible')) {
    if (!empty($variables['renderer']->flexible)) {
      $variables['flexible_editor'] = TRUE;
      $flexible_layout = layout_flexible_tempstore_load($variables['layout_info']['name']);
    }
    else {
      $variables['flexible_editor'] = FALSE;
      $flexible_layout = layout_flexible_template_load($variables['layout_info']['name']);
    }
    $variables['region_buttons'] = array();
    if (isset($variables['renderer']->region_buttons)) {
      $variables['region_buttons'] = $variables['renderer']->region_buttons;
    }

    $variables['column_data'] = layout_flexible_row_styles();

    $variables['rows'] = $flexible_layout->rows;
    $variables['row_data'] = array();
    foreach ($variables['rows'] as $name => $row) {
      $container = ($row['container'] == 'container') ? 'container container-fluid' : (($row['container'] == 'container_fluid') ? 'container-fluid' : 'no-container');
      $row['row_class'] = $container . ' flexible-row--' . $name . ' ' . $row['contains'] . ' ' . $row['classes'];
      $row['row_id'] = $variables['flexible_editor'] ? 'id = "flexible-row--' . $name . '"' : '';
      $row['element'] = !empty($row['element']) ? $row['element'] : 'div';
      if ($row['contains'] == 'region_12') {
        if (!empty($row['region_names']['region_name_0'])) {
          $region_name = $row['region_names']['region_name_0'];
        }
        else {
          $region_name = $name;
        }
        $row['regions'][0]['region_md'] = '12';
        $row['regions'][0]['region_name'] = $region_name;
        $row['regions'][0]['content_key'] = $variables['flexible_editor'] ? $name : $name . '--0';
      }
      else {
        $col_info = $variables['column_data'][$row['contains']];
        $split = explode(':', $col_info['bootstrap']);
        $i = 0;
        foreach ($split as $col) {
          if (!empty($row['region_names']['region_name_' . $i])) {
            $region_name = $row['region_names']['region_name_' . $i];
          }
          else {
            $region_name = $name . ' ' . $i;
          }
          $row['regions'][] = array(
            'region_md' => $col,
            'region_name' => $region_name,
            'content_key' => $variables['flexible_editor'] ? $name : $name . '--' . $i,
          );
          $i++;
        }
      }
      $variables['row_data'][$name] = $row;
    }

  }
}