commit 8ce24d2b56f7364b26bbf046fd5fc3b895f7db52 Author: Damien Tournoud Date: Mon Jul 4 18:57:05 2011 +0200 Issue #1208864 - option 2: automatically determine the 'page' flag by the view mode. diff --git a/entity.api.php b/entity.api.php index affda7c..b2b2227 100644 --- a/entity.api.php +++ b/entity.api.php @@ -121,6 +121,12 @@ * This is optional, but suggested for the Rules integration, and required for * the admin ui (see above). * + * In addition, entity types that are displayed by entity_view() support the + * following addition to the 'view modes' array: + * - page: (optional) if set, determine the way this view mode will be displayed: + * if TRUE a full page will be assumed and no title will be displayed, if + * FALSE, a title for the entity will be rendered. + * * @see hook_entity_info() * @see entity_metadata_hook_entity_info() */ diff --git a/entity.module b/entity.module index 7ec5f13..5dae6c2 100644 --- a/entity.module +++ b/entity.module @@ -801,9 +801,8 @@ function template_preprocess_entity(&$variables) { $info = entity_get_info($entity_type); $variables['title'] = check_plain(entity_label($entity_type, $entity)); - $uri = entity_uri($entity_type, $entity); - $variables['url'] = $uri ? url($uri['path'], $uri['options']) : FALSE; - $variables['page'] = $uri && $uri['path'] == $_GET['q']; + $variables['url'] = $variables['elements']['#url']; + $variables['page'] = $variables['elements']['#page']; // Helpful $content variable for templates. $variables['content'] = array(); diff --git a/includes/entity.controller.inc b/includes/entity.controller.inc index 7244c38..f4a2c1c 100644 --- a/includes/entity.controller.inc +++ b/includes/entity.controller.inc @@ -462,6 +462,26 @@ class EntityAPIController extends DrupalDefaultEntityController implements Entit '#view_mode' => $view_mode, '#language' => $langcode, ); + + // Determine the URL of the entity. + if (!isset($build['#url'])) { + $uri = entity_uri($this->entityType, $entity); + $build['#url'] = $uri ? url($uri['path'], $uri['options']) : FALSE; + } + + // Determine if we are viewing the entity in page mode. + if (!isset($build['#page'])) { + if (isset($this->entityInfo['view modes'][$view_mode]['page'])) { + // Use the information from the view mode if present. + $build['#page'] = $this->entityInfo['view modes']['page']; + } + else { + // Fall-back to a (not really good) heuristic, that matches what + // core does for nodes. + $build['#page'] = $uri && $uri['path'] == $_GET['q']; + } + } + // Allow modules to modify the structured entity. drupal_alter(array($this->entityType . '_view', 'entity_view'), $build, $this->entityType); $key = isset($entity->{$this->idKey}) ? $entity->{$this->idKey} : NULL;