You are here

function ds_entity_variables in Display Suite 7

Same name and namespace in other branches
  1. 7.2 ds.module \ds_entity_variables()

Add variables to an entity.

This function is added in ds_theme_registry_alter().

1 call to ds_entity_variables()
ds_extras_preprocess_view_layout in modules/ds_extras/ds_extras.module
Implements hook_preprocess_views_view().
1 string reference to 'ds_entity_variables'
_ds_theme_registry_alter in ./ds.registry.inc
Implements hook_theme_registry_alter().

File

./ds.module, line 803
Display Suite core functions.

Code

function ds_entity_variables(&$vars) {
  if (isset($vars['elements']) && isset($vars['elements']['#bundle']) && ($layout = ds_get_layout($vars['elements']['#entity_type'], $vars['elements']['#bundle'], $vars['elements']['#view_mode']))) {

    // Do not render panel layouts.
    if (!empty($layout['settings']['ds_panels'])) {
      return;
    }
    $render_container = 'content';

    // User uses user_profile as container.
    if ($vars['elements']['#entity_type'] == 'user') {
      $render_container = 'user_profile';
    }

    // Move any preprocess fields to render container.
    // Inconsitency in taxonomy term naming.
    $object = $vars['elements']['#entity_type'];
    if ($vars['elements']['#entity_type'] == 'taxonomy_term') {
      $object = 'term';
    }
    if (isset($vars[$object]->preprocess_fields)) {
      foreach ($vars[$object]->preprocess_fields as $key => $field) {

        // Process RDF if the module is enabled before moving preprocess fields.
        if (module_exists('rdf')) {
          rdf_process($vars, $field);

          // Remove it so we can unset the field later on.
          unset($vars['rdf_template_variable_attributes_array'][$field]);
        }

        // Move the field to content so it renders, remove it
        // because we don't need it anymore.
        if (isset($vars[$field])) {
          $vars[$render_container][$field] = $vars[$field];
          if (!isset($vars['preprocess_keep'])) {
            unset($vars[$field]);
          }
        }
      }
    }

    // Hide empty regions variable.
    $hide_empty_regions = $layout['settings']['hide_empty_regions'];

    // Check if this is a flexible panels layout.
    if (!empty($layout['flexible'])) {
      ctools_include('plugins', 'panels');
      $vars['css_id'] = $vars['settings'] = $vars['display'] = $vars['renderer'] = '';
      $vars['layout'] = panels_get_layout($layout['panels']['name']);
      $vars['theme_hook_suggestion'] = 'panels_flexible';
    }
    else {

      // Template layout.
      if (!isset($vars['classes_array'])) {
        $vars['classes_array'] = array();
      }
      $vars['classes_array'][] = 'view-mode-' . $vars['elements']['#view_mode'];

      // In case this is a panels layout, use panels info array.
      if (isset($layout['module']) && $layout['module'] == 'panels') {
        $layout['layout'] = $layout['panels']['theme'];
      }
      $vars['theme_hook_suggestions'][] = $layout['layout'];
      $vars['theme_hook_suggestions'][] = $layout['layout'] . '__' . $vars['elements']['#entity_type'];
      $vars['theme_hook_suggestions'][] = $layout['layout'] . '__' . $vars['elements']['#entity_type'] . '_' . $vars['elements']['#bundle'];
      $vars['theme_hook_suggestions'][] = $layout['layout'] . '__' . $vars['elements']['#entity_type'] . '_' . $vars['elements']['#bundle'] . '_' . $vars['elements']['#view_mode'];
    }

    // Allow modules to alter the region layout before it is rendered.
    drupal_alter('ds_regions', $layout, $vars[$object]);

    // Create region variables based on the layout settings.
    foreach ($layout['regions'] as $region_name => $region) {

      // Create the region content.
      $vars[$region_name] = ds_render_region($vars[$render_container], $region_name, $layout);

      // Hide empty regions.
      if ($hide_empty_regions && empty($vars[$region_name]) && empty($layout['flexible'])) {
        $vars[$region_name] = FALSE;
      }
      elseif (empty($vars[$region_name])) {
        $vars[$region_name] = ' ';
      }

      // In case this is a panels layout, add the variable to the $content variable.
      if (isset($layout['module']) && $layout['module'] == 'panels') {
        $vars['content'][$region_name] = $vars[$region_name];
        unset($vars[$region_name]);
      }

      // Add extras classes to the region.
      if (empty($layout['flexible'])) {
        $vars[$region_name . '_classes'] = !empty($layout['settings']['classes'][$region_name]) ? ' ' . implode(' ', $layout['settings']['classes'][$region_name]) : '';
      }
    }

    // Let other modules know we have rendered.
    $vars['rendered_by_ds'] = TRUE;
  }
}