Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Implements hook_alpha_page_structure_alter().
- */
- function YOURTHEMENAME_alpha_page_structure_alter(&$vars) {
- foreach (element_children($vars) as $section) {
- if (isset($vars[$section]['#section'])) {
- foreach (element_children($vars[$section]) as $zone) {
- _YOURTHEMENAME_calculate_first_last($vars[$section][$zone]);
- }
- }
- }
- }
- /**
- * Implements hook_alpha_preprocess_region().
- */
- function YOURTHEMENAME_alpha_preprocess_region(&$vars) {
- if (!empty($vars['elements']['#grid']['first_column']) && $vars['elements']['#grid']['first_column'] == TRUE) {
- $vars['attributes_array']['class'][] = 'grid-first-column';
- }
- if (!empty($vars['elements']['#grid']['last_column']) && $vars['elements']['#grid']['last_column'] == TRUE) {
- $vars['attributes_array']['class'][] = 'grid-last-column';
- }
- }
- /**
- * Helper function to calculate which regions are positioned first and last
- * in the grid, within a given zone.
- */
- function _YOURTHEMENAME_calculate_first_last(&$zone) {
- $regions = array();
- $sort_fields = array();
- $count = 1;
- foreach (element_children($zone) as $region) {
- $regions[] = $region;
- $sort_fields['position'][] = (!empty($zone[$region]['#position'])) ? $zone[$region]['#position'] : 0;
- $sort_fields['original_order'][] = $count;
- $count ++;
- }
- if (isset($zone['#data']['order']) && $zone['#data']['order'] == TRUE) {
- array_multisort($sort_fields['position'], $sort_fields['original_order'], $regions);
- }
- $columns = $zone['#data']['columns'];
- $current_position = 0;
- $previous_region = '';
- foreach ($regions as $region) {
- $total_width = $zone[$region]['#grid']['prefix'] + $zone[$region]['#grid']['columns'] + $zone[$region]['#grid']['suffix'];
- if ($current_position == 0) {
- $zone[$region]['#grid']['first_column'] = TRUE;
- }
- else if (!empty($previous_region) && $current_position + $total_width > $columns) {
- $zone[$previous_region]['#grid']['last_column'] = TRUE;
- $zone[$region]['#grid']['first_column'] = TRUE;
- $current_position = 0;
- }
- $current_position += $total_width;
- $previous_region = $region;
- }
- if (!empty($previous_region)) {
- $zone[$previous_region]['#grid']['last_column'] = TRUE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment