comparison openmindattribute/openmindattribute.module @ 11:61dd2a96c4e2

add redirect /entity/%openmind_id as menu hook.
author casties
date Mon, 06 Jul 2015 18:53:41 +0200
parents cf772424f725
children 797c6051e489
comparison
equal deleted inserted replaced
10:2a786f0d46a7 11:61dd2a96c4e2
1 <?php 1 <?php
2 2
3 3
4 /**
5 * Implements hook_menu()
6 */
7 function openmindattribute_menu() {
8 // path location
9 $items['entity/%'] = array(
10 // page title
11 'title' => 'OpenMind Entity',
12 // describe the page for the menu system. site visitors will not see this
13 'description' => 'OpenMind hook_menu() for redirecting entities.',
14 // function that is called when visiting the new path
15 'page callback' => '_openmindattribute_redirect_entity',
16 // permissions required to view page
17 'access arguments' => array('access content'),
18 // arguments to page callback
19 'page arguments' => array(1),
20 );
21 return $items;
22 }
23
24 /**
25 * Redirect to the node with the given OpenMind entity id.
26 *
27 * @param unknown $ent_id
28 */
29 function _openmindattribute_redirect_entity($ent_id) {
30 $query = new EntityFieldQuery();
31
32 $query->entityCondition('entity_type', 'node')
33 ->entityCondition('bundle', 'openmind_entity')
34 ->propertyCondition('status', NODE_PUBLISHED)
35 ->fieldCondition('field_id', 'value', $ent_id, '=');
36
37 $result = $query->execute();
38
39 if (isset($result['node'])) {
40 $nids = array_keys($result['node']);
41 drupal_goto('node/' . $nids[0]);
42 }
43 }
4 44
5 /** 45 /**
6 * Implements hook_field_info(). 46 * Implements hook_field_info().
7 */ 47 */
8 function openmindattribute_field_info() { 48 function openmindattribute_field_info() {