diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-04-06 19:49:03 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-04-06 19:49:03 +0000 |
commit | ba96cffdb7d3f76254ff7391523a6fc34abf10e2 (patch) | |
tree | dd42dc052efda70657a1e73ab1e47964c920d734 /includes | |
parent | c2b1029595afe103b5f1533604cfe658755f1f8d (diff) | |
download | brdo-ba96cffdb7d3f76254ff7391523a6fc34abf10e2.tar.gz brdo-ba96cffdb7d3f76254ff7391523a6fc34abf10e2.tar.bz2 |
- Patch #699440 by scor, effulgentsia, noahb, catch: add bundle support to entity_uri() callback to remove performance overhead of forum_url_outbound_alter().
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/includes/common.inc b/includes/common.inc index 12474d3c4..d29715c6a 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -6430,11 +6430,42 @@ function entity_prepare_view($entity_type, $entities) { * uri of its own. */ function entity_uri($entity_type, $entity) { - $info = entity_get_info($entity_type); - if (isset($info['uri callback']) && function_exists($info['uri callback'])) { - return $info['uri callback']($entity) + array('options' => array()); + // This check enables the URI of an entity to be easily overridden from what + // the callback for the entity type or bundle would return, and it helps + // minimize performance overhead when entity_uri() is called multiple times + // for the same entity. + if (!isset($entity->uri)) { + $info = entity_get_info($entity_type); + list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); + + // A bundle-specific callback takes precedence over the generic one for the + // entity type. + if (isset($info['bundles'][$bundle]['uri callback'])) { + $uri_callback = $info['bundles'][$bundle]['uri callback']; + } + elseif (isset($info['uri callback'])) { + $uri_callback = $info['uri callback']; + } + else { + $uri_callback = NULL; + } + + // Invoke the callback to get the URI. If there is no callback, set the + // entity's 'uri' property to FALSE to indicate that it is known to not have + // a URI. + if (isset($uri_callback) && function_exists($uri_callback)) { + $entity->uri = $uri_callback($entity); + if (!isset($entity->uri['options'])) { + $entity->uri['options'] = array(); + } + } + else { + $entity->uri = FALSE; + } } + return $entity->uri ? $entity->uri : NULL; } + /** * Invokes entity insert/update hooks. * |