Mercurial > hg > drupalISMI
changeset 11:61dd2a96c4e2
add redirect /entity/%openmind_id as menu hook.
author | casties |
---|---|
date | Mon, 06 Jul 2015 18:53:41 +0200 |
parents | 2a786f0d46a7 |
children | 797c6051e489 |
files | openmindattribute/openmindattribute.module |
diffstat | 1 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/openmindattribute/openmindattribute.module Fri Jun 26 10:59:53 2015 +0200 +++ b/openmindattribute/openmindattribute.module Mon Jul 06 18:53:41 2015 +0200 @@ -1,6 +1,46 @@ <?php +/** + * Implements hook_menu() + */ +function openmindattribute_menu() { + // path location + $items['entity/%'] = array( + // page title + 'title' => 'OpenMind Entity', + // describe the page for the menu system. site visitors will not see this + 'description' => 'OpenMind hook_menu() for redirecting entities.', + // function that is called when visiting the new path + 'page callback' => '_openmindattribute_redirect_entity', + // permissions required to view page + 'access arguments' => array('access content'), + // arguments to page callback + 'page arguments' => array(1), + ); + return $items; +} + +/** + * Redirect to the node with the given OpenMind entity id. + * + * @param unknown $ent_id + */ +function _openmindattribute_redirect_entity($ent_id) { + $query = new EntityFieldQuery(); + + $query->entityCondition('entity_type', 'node') + ->entityCondition('bundle', 'openmind_entity') + ->propertyCondition('status', NODE_PUBLISHED) + ->fieldCondition('field_id', 'value', $ent_id, '='); + + $result = $query->execute(); + + if (isset($result['node'])) { + $nids = array_keys($result['node']); + drupal_goto('node/' . $nids[0]); + } +} /** * Implements hook_field_info().