[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/ctools/plugins/relationships/ -> term_from_node.inc (source)

   1  <?php
   2  // $Id: term_from_node.inc,v 1.2.2.3 2010/01/29 20:18:26 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   * Plugin to provide an relationship handler for term from node.
   7   */
   8  
   9  /**
  10   * Plugins are described by creating a $plugin array which will be used
  11   * by the system that includes this file.
  12   */
  13  $plugin = array(
  14    'title' => t('Term from node'),
  15    'keyword' => 'term',
  16    'description' => t('Adds a taxonomy term from a node context; if multiple terms are selected, this will get the "first" term only.'),
  17    'required context' => new ctools_context_required(t('Node'), 'node'),
  18    'context' => 'ctools_term_from_node_context',
  19    'settings form' => 'ctools_term_from_node_settings_form',
  20    'settings form validate' => 'ctools_term_from_node_settings_form_validate',
  21    'defaults' => array('vid' => ''),
  22  );
  23  
  24  /**
  25   * Return a new context based on an existing context.
  26   */
  27  function ctools_term_from_node_context($context, $conf) {
  28    // If unset it wants a generic, unfilled context, which is just NULL.
  29    if (empty($context->data)) {
  30      return ctools_context_create_empty('term', NULL);
  31    }
  32  
  33    if (isset($context->data->taxonomy)) {
  34      foreach ($context->data->taxonomy as $term) {
  35        if ($term->vid == $conf['vid']) {
  36          return ctools_context_create('term', $term);
  37        }
  38      }
  39    }
  40  }
  41  
  42  /**
  43   * Settings form for the relationship.
  44   */
  45  function ctools_term_from_node_settings_form($conf) {
  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="clear-block">',
  56      '#suffix' => '</div>',
  57    );
  58  
  59    return $form;
  60  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7