1 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

core/modules/layout/layout.theme.inc, line 288
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 (is_a($variables['renderer'], 'LayoutRendererFlexible')) {
      $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();

    $variables['row_widths'] = array(
      'container' => t('Fixed maximum width'),
      'container_fluid' => t('Fluid width'),
      'no_container' => t('Full width'),
    );
    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';
      $row['row_label'] = t('@element row', array('@element' => "<$row[element]>"));
      if ($row['contains'] == 'region_12') {
        $region_classes = '';
        if (!empty($row['region_names']['region_0'])) {
          $region_name = $row['region_names']['region_0']['label'];
          $class_name = isset($row['region_names']['region_0']['name']) ? $row['region_names']['region_0']['name'] : backdrop_html_class($row['region_names']['region_0']['label']);
          $region_classes .= 'l-region--' . $class_name;
          $custom_classes = !empty($row['region_names']['region_0']['classes']) ? ' ' . _layout_clean_custom_css($row['region_names']['region_0']['classes']) : '';
          $region_classes .= !empty($row['region_names']['region_0']['region_class_enable']) ? $custom_classes : '';
        }
        else {
          $region_name = $name;
          $region_classes .= 'l-region--' . backdrop_html_class($name);
        }
        $row['regions'][0]['region_md'] = '12';
        $row['regions'][0]['region_name'] = $region_name;
        $row['regions'][0]['region_classes'] = $region_classes;
        $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) {
          $region_classes = '';
          if (!empty($row['region_names']['region_' . $i])) {
            $region_name = $row['region_names']['region_' . $i]['label'];
            $class_name = isset($row['region_names']['region_' . $i]['name']) ? $row['region_names']['region_' . $i]['name'] : backdrop_html_class($row['region_names']['region_' . $i]['label']);
            $region_classes .= 'l-region--' . $class_name;
            $custom_classes = !empty($row['region_names']['region_' . $i]['classes']) ? ' ' . _layout_clean_custom_css($row['region_names']['region_' . $i]['classes']) : '';
            $region_classes .= !empty($row['region_names']['region_' . $i]['region_class_enable']) ? $custom_classes : '';
          }
          else {
            $region_name = $name . ' ' . $i;
            $region_classes .= 'l-region--' . backdrop_html_class($name . ' ' . $i);
          }
          $row['regions'][] = array(
            'region_md' => $col,
            'region_name' => $region_name,
            'region_classes' => $region_classes,
            'content_key' => $variables['flexible_editor'] ? $name : $name . '--' . $i,
          );
          $i++;
        }
      }
      $variables['row_data'][$name] = $row;
    }

  }
}