You are here

function commerce_preprocess_entity in Commerce Core 7

Processes variables for entity.tpl.php, replacing template_preprocess_entity().

@todo Remove when https://drupal.org/node/1934382 is resolved.

See also

commerce_theme_registry_alter()

1 string reference to 'commerce_preprocess_entity'
commerce_theme_registry_alter in ./commerce.module
Implements hook_theme_registry_alter().

File

./commerce.module, line 1313
Defines features and functions common to the Commerce modules.

Code

function commerce_preprocess_entity(&$variables) {
  $variables['view_mode'] = $variables['elements']['#view_mode'];
  $entity_type = $variables['elements']['#entity_type'];
  $variables['entity_type'] = $entity_type;
  $entity = $variables['elements']['#entity'];
  $variables[$variables['elements']['#entity_type']] = $entity;
  $info = entity_get_info($entity_type);
  $variables['title'] = check_plain(entity_label($entity_type, $entity));
  $uri = entity_uri($entity_type, $entity);
  $variables['url'] = $uri && isset($uri['path']) ? url($uri['path'], $uri['options']) : FALSE;
  if (isset($variables['elements']['#page'])) {

    // If set by the caller, respect the page property.
    $variables['page'] = $variables['elements']['#page'];
  }
  else {

    // Else, try to automatically detect it.
    $variables['page'] = $uri && isset($uri['path']) && $uri['path'] == $_GET['q'];
  }

  // Helpful $content variable for templates.
  $variables['content'] = array();
  foreach (element_children($variables['elements']) as $key) {
    $variables['content'][$key] = $variables['elements'][$key];
  }
  if (!empty($info['fieldable'])) {

    // Make the field variables available with the appropriate language.
    field_attach_preprocess($entity_type, $entity, $variables['content'], $variables);
  }
  list(, , $bundle) = entity_extract_ids($entity_type, $entity);

  // Gather css classes.
  $variables['classes_array'][] = drupal_html_class('entity-' . $entity_type);
  $variables['classes_array'][] = drupal_html_class($entity_type . '-' . $bundle);

  // Add RDF type and about URI.
  if (module_exists('rdf')) {
    $variables['attributes_array']['about'] = empty($uri['path']) ? NULL : url($uri['path']);
    $variables['attributes_array']['typeof'] = empty($entity->rdf_mapping['rdftype']) ? NULL : $entity->rdf_mapping['rdftype'];
  }

  // Add suggestions.
  $variables['theme_hook_suggestions'][] = $entity_type;
  $variables['theme_hook_suggestions'][] = $entity_type . '__' . $bundle;
  $variables['theme_hook_suggestions'][] = $entity_type . '__' . $bundle . '__' . $variables['view_mode'];
  if ($id = entity_id($entity_type, $entity)) {
    $variables['theme_hook_suggestions'][] = $entity_type . '__' . $id;
  }
}