diff --git a/ds.module b/ds.module index 18cf504..9c5c3cf 100644 --- a/ds.module +++ b/ds.module @@ -526,6 +526,8 @@ function ds_field_attach_view_alter(&$build, $context) { * This function is added in ds_theme_registry_alter(). */ function ds_entity_variables(&$vars) { + $start = microtime(TRUE); + if (isset($vars['elements']) && $layout = ds_get_layout($vars['elements']['#entity_type'], $vars['elements']['#bundle'], $vars['elements']['#view_mode'])) { // Do not render panel layouts. @@ -546,7 +548,7 @@ function ds_entity_variables(&$vars) { $object = 'term'; } if (isset($vars[$object]->preprocess_fields)) { - foreach ($vars[$object]->preprocess_fields as $key => $field) { + foreach ($vars[$object]->preprocess_fields as $field) { // Process RDF if the module is enabled before moving preprocess fields. if (module_exists('rdf')) { @@ -594,17 +596,23 @@ function ds_entity_variables(&$vars) { } // Create region variables based on the layout settings. + $layout_render_array = array(); foreach ($layout['regions'] as $region_name => $region) { // Create the region content. - $vars[$region_name] = ds_render_region($vars[$render_container], $region_name, $layout); + $layout_render_array[$region_name] = array(); + if (isset($layout['settings']['regions'][$region_name])) { + foreach ($layout['settings']['regions'][$region_name] as $field) { + $layout_render_array[$region_name][] = $vars[$render_container][$field]; + } + } // Hide empty regions. - if ($hide_empty_regions && empty($vars[$region_name]) && empty($layout['flexible'])) { - $vars[$region_name] = FALSE; + if ($hide_empty_regions && empty($layout_render_array[$region_name]) && empty($layout['flexible'])) { + unset($layout_render_array[$region_name]); } - elseif (empty($vars[$region_name])) { - $vars[$region_name] = ' '; + elseif (empty($layout_render_array[$region_name])) { + $vars[$region_name] = array('#markup' => ' '); } // In case this is a panels layout, add the variable to the $content variable. @@ -619,27 +627,16 @@ function ds_entity_variables(&$vars) { } } } -} -/** - * Render a region. - * - * @param $content - * An array of content fields. - * @param $region - * The name of region to render. - * @param $layout - * The layout definition. - */ -function ds_render_region($content, $region, $layout) { - $output = ''; - - if (isset($layout['settings']['regions'][$region])) { - foreach ($layout['settings']['regions'][$region] as $key => $field) { - $output .= render($content[$field]); - } + // Let other modules alter the ds array before creating the region variables. + drupal_alter('ds_prerender', $layout_render_array); + foreach ($layout_render_array as $region_name => $content) { + $vars[$region_name] = render($content); } - return $output; + + $end = microtime(TRUE); + $diff = round(($start - $end) * 1000, 4); + dsm("Diff - $diff"); } /**