[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

   1  <?php
   2  // $Id: terms_from_node.inc,v 1.1.2.1 2010/02/23 22:09:47 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   * Plugin to provide an relationship handler for all terms 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('Multiple terms from node'),
  15    'keyword' => 'terms',
  16    'description' => t('Adds a taxonomy terms from a node context; if multiple terms are selected, they wil be concatenated.'),
  17    'required context' => new ctools_context_required(t('Node'), 'node'),
  18    'context' => 'ctools_terms_from_node_context',
  19    'settings form' => 'ctools_terms_from_node_settings_form',
  20    'settings form validate' => 'ctools_terms_from_node_settings_form_validate',
  21    'defaults' => array('vid' => array(), 'concatenator' => ','),
  22  );
  23  
  24  /**
  25   * Return a new context based on an existing context.
  26   */
  27  function ctools_terms_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('terms', NULL);
  31    }
  32  
  33    // Collect all terms for the chosen vocabulary and concatenate them.
  34    if (isset($context->data->taxonomy)) {
  35      $terms = array();
  36      foreach ($context->data->taxonomy as $term) {
  37        if (in_array($term->vid, $conf['vid'])) {
  38          $terms[] = $term->tid;
  39        }
  40      }
  41  
  42      if (!empty($terms)) {
  43        $all_terms = ctools_break_phrase(implode($conf['concatenator'], $terms));
  44        return ctools_context_create('terms', $all_terms);
  45      }
  46    }
  47  }
  48  
  49  /**
  50   * Settings form for the relationship.
  51   */
  52  function ctools_terms_from_node_settings_form($conf) {
  53    $options = array();
  54    foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
  55      $options[$vid] = $vocabulary->name;
  56    }
  57    $form['vid'] = array(
  58      '#title' => t('Vocabulary'),
  59      '#type' => 'checkboxes',
  60      '#options' => $options,
  61      '#default_value' => $conf['vid'],
  62      '#prefix' => '<div class="clear-block">',
  63      '#suffix' => '</div>',
  64    );
  65    $form['concatenator'] = array(
  66      '#title' => t('Concatenator'),
  67      '#type' => 'select',
  68      '#options' => array(',' => ', (AND)', '+' => '+ (OR)'),
  69      '#default_value' => $conf['concatenator'],
  70      '#prefix' => '<div class="clear-block">',
  71      '#suffix' => '</div>',
  72      '#description' => t("When the value from this context is passed on to a view as argument, the terms can be concatenated in the form of 1+2+3 (for OR) or 1,2,3 (for AND)."),
  73    );
  74  
  75    return $form;
  76  }


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