Projet

Général

Profil

Paste
Télécharger (780 octets) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / menu_token / plugins / menu_token_entity_random.inc @ 27370441

1 85ad3d82 Assos Assos
<?php
2
3
class menu_token_entity_random implements menu_token_handler {
4
  function form_options($options) {
5
    // Nothing to do here.
6
  }
7
8
  function form_submit($form, &$form_state) {
9
    // Nothing to do here.
10
  }
11
12
  function form_validate($form, &$form_state) {
13
    // Nothing to do here.
14
  }
15
16
  function form_alter(&$form, &$form_state) {
17
    // Nothing to do here.
18
  }
19
20
  function object_load($options) {
21
    $entity_type = $options['_type'];
22
    $info = entity_get_info($entity_type);
23
24
    $id =
25
      db_select($info['base table'], 'e')
26
      ->fields('e', array($info['entity keys']['id']))
27
      ->orderRandom()
28
      ->range(0, 1)
29
      ->execute()
30
      ->fetchField(0);
31
32
    if ($id) {
33
      return entity_load_single($entity_type, $id);
34
    }
35
36
    return FALSE;
37
  }
38
}