diff --git a/ds.api.php b/ds.api.php index 20a0265..e2dbfba 100644 --- a/ds.api.php +++ b/ds.api.php @@ -410,6 +410,22 @@ function hook_ds_layout_info() { } /** + * Alter the layout render array. + * + * @param $layout_render_array + * The render array + * @param $context + * An array with the context that is being rendered. Available keys are + * - entity + * - entity_type + * - bundle + * - view_mode + */ +function hook_ds_pre_render_alter(&$layout_render_array, $context) { + $layout_render_array['left'][] = array('#markup' => 'cool!', '#weight' => 20); +} + +/** * Alter layouts found by Display Suite. * * @param $layouts diff --git a/ds.module b/ds.module index 265a4c2..60b7b4d 100644 --- a/ds.module +++ b/ds.module @@ -885,7 +885,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')) { @@ -934,7 +934,16 @@ function ds_entity_variables(&$vars) { 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) { + // Make sure the field exists. + if (!isset($vars[$render_container][$field])) { + continue; + } + $layout_render_array[$region_name][] = $vars[$render_container][$field]; + } + } // In case this is a panels layout, add the variable to the $content variable. if (isset($layout['module']) && $layout['module'] == 'panels') { @@ -954,41 +963,14 @@ function ds_entity_variables(&$vars) { // Add a layout wrapper $vars['layout_wrapper'] = isset($layout['settings']['layout_wrapper']) ? $layout['settings']['layout_wrapper'] : 'div'; - } -} - -/** - * 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) { - - // Make sure the field exists. - if (!isset($content[$field])) { - continue; - } - // Safe-guard against strings. - if (is_string($content[$field])) { - $output .= $content[$field]; - } - else { - $output .= drupal_render($content[$field]); - } + // Let other modules alter the ds array before creating the region variables. + $context = array('entity' => $object, 'entity_type' => $vars['elements']['#entity_type'], 'bundle' => $vars['elements']['#bundle'], 'view_mode' => $vars['elements']['#view_mode']); + drupal_alter('ds_pre_render', $layout_render_array, $context); + foreach ($layout_render_array as $region_name => $content) { + $vars[$region_name] = drupal_render($content); } } - - return $output; } /**