comparison sites/all/modules/ctools/plugins/relationships/term_from_node.inc @ 0:ff03f76ab3fe

initial version
author danieleb <danielebarchiesi@me.com>
date Wed, 21 Aug 2013 18:51:11 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:ff03f76ab3fe
1 <?php
2
3 /**
4 * @file
5 * Plugin to provide an relationship handler for term from node.
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('Term from node'),
14 'keyword' => 'term',
15 'description' => t('Adds a taxonomy term from a node context; if multiple terms are selected, this will get the "first" term only.'),
16 'required context' => new ctools_context_required(t('Node'), 'node'),
17 'context' => 'ctools_term_from_node_context',
18 'edit form' => 'ctools_term_from_node_settings_form',
19 'defaults' => array('vid' => ''),
20 );
21
22 /**
23 * Return a new context based on an existing context.
24 */
25 function ctools_term_from_node_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('entity:taxonomy_term', NULL);
29 }
30
31 if (isset($context->data->taxonomy)) {
32 foreach ($context->data->taxonomy as $term) {
33 if ($term->vid == $conf['vid']) {
34 return ctools_context_create('entity:taxonomy_term', $term);
35 }
36 }
37 }
38 }
39
40 /**
41 * Settings form for the relationship.
42 */
43 function ctools_term_from_node_settings_form($form, &$form_state) {
44 $conf = $form_state['conf'];
45
46 $options = array();
47 foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
48 $options[$vid] = $vocabulary->name;
49 }
50 $form['vid'] = array(
51 '#title' => t('Vocabulary'),
52 '#type' => 'select',
53 '#options' => $options,
54 '#default_value' => $conf['vid'],
55 '#prefix' => '<div class="clearfix">',
56 '#suffix' => '</div>',
57 );
58
59 return $form;
60 }