Projet

Général

Profil

Paste
Télécharger (1,73 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / relationships / book_parent.inc @ 6e3ce7c2

1
<?php
2

    
3
/**
4
 * @file
5
 * Plugin to provide an relationship handler for book parent.
6
 */
7

    
8
/**
9
 * Plugins are described by creating a $plugin array which will be used
10
 * by the system that includes this file.
11
 */
12
$plugin = array(
13
  'title' => t('Book parent'),
14
  'keyword' => 'book_parent',
15
  'description' => t('Adds a book parent from a node context.'),
16
  'required context' => new ctools_context_required(t('Node'), 'node'),
17
  'context' => 'ctools_book_parent_context',
18
  'edit form' => 'ctools_book_parent_settings_form',
19
  'defaults' => array('type' => 'top'),
20
);
21

    
22
/**
23
 * Return a new context based on an existing context.
24
 */
25
function ctools_book_parent_context($context, $conf) {
26
  // If unset it wants a generic, unfilled context, which is just NULL.
27
  if (empty($context->data)) {
28
    return ctools_context_create_empty('node');
29
  }
30

    
31
  if (isset($context->data->book)) {
32
    if ($conf['type'] == 'top') {
33
      $nid = $context->data->book['bid'];
34
    }
35
    else {
36
      // Just load the parent book.
37
      $item = book_link_load($context->data->book['plid']);
38
      $nid = $item['nid'];
39
    }
40

    
41
    if (!empty($nid)) {
42
      // Load the node.
43
      $node = node_load($nid);
44
      // Generate the context.
45
      if (node_access('view', $node)) {
46
        return ctools_context_create('node', $node);
47
      }
48
    }
49
  }
50
  else {
51
    return ctools_context_create_empty('node');
52
  }
53
}
54

    
55
/**
56
 * Settings form for the relationship.
57
 */
58
function ctools_book_parent_settings_form($form, &$form_state) {
59
  $conf = $form_state['conf'];
60
  $form['type'] = array(
61
    '#type' => 'select',
62
    '#title' => t('Relationship type'),
63
    '#options' => array('parent' => t('Immediate parent'), 'top' => t('Top level book')),
64
    '#default_value' => $conf['type'],
65
  );
66

    
67
  return $form;
68
}