[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

   1  <?php
   2  // $Id: node_from_view.inc,v 1.1.2.1 2010/07/20 00:17:09 merlinofchaos Exp $
   3  
   4  /**
   5   * @file
   6   * Plugin to provide an relationship handler for node from view.
   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('Node from view'),
  15    'keyword' => 'node',
  16    'description' => t('Extract a node context from a view context of the base type node.'),
  17    'required context' => new ctools_context_required(t('View'), 'view', array('base' => 'node')),
  18    'context' => 'views_content_node_from_view_context',
  19    'settings form' => 'views_content_node_from_view_settings_form',
  20    'settings form validate' => 'views_content_node_from_view_settings_form_validate',
  21    'defaults' => array('row' => 1),
  22  );
  23  
  24  /**
  25   * Return a new context based on an existing context.
  26   */
  27  function views_content_node_from_view_context($context, $conf, $placeholder = FALSE) {
  28    // If unset it wants a generic, unfilled context, which is just NULL.
  29    if (empty($context->data) || $placeholder) {
  30      return ctools_context_create_empty('node', NULL);
  31    }
  32    $view = views_content_context_get_view($context);
  33    // Ensure the view executes, but we don't need its output.
  34    views_content_context_get_output($context);
  35  
  36    $row = intval($conf['row']) - 1;
  37    if (isset($view->result[$row])) {
  38      $nid = $view->result[$row]->{$view->base_field};
  39      if ($nid) {
  40        $node = node_load($nid);
  41        return ctools_context_create('node', $node);
  42      }
  43    }
  44    return ctools_context_create_empty('node', NULL);
  45  }
  46  
  47  /**
  48   * Settings form for the relationship.
  49   */
  50  function views_content_node_from_view_settings_form($conf) {
  51    $form['row'] = array(
  52      '#title' => t('Row number'),
  53      '#type' => 'textfield',
  54      '#default_value' => $conf['row'],
  55    );
  56  
  57    return $form;
  58  }
  59  
  60  function views_content_node_from_view_settings_form_validate($form, &$form_values, &$form_state) {
  61    if (intval($form_values['row']) <= 0) {
  62      form_error($form['row'], t('Row number must be a positive integer value.'));
  63    }
  64  }


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