# HG changeset patch # User casties # Date 1436201621 -7200 # Node ID 61dd2a96c4e2571346c1a0e2a4a832bcce0ceaaa # Parent 2a786f0d46a76ccbfae01f3cc6c006020de28d8d add redirect /entity/%openmind_id as menu hook. diff -r 2a786f0d46a7 -r 61dd2a96c4e2 openmindattribute/openmindattribute.module --- 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 @@ '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().