/[drupal]/contributions/modules/views/modules/node/views_plugin_argument_validate_node.inc
ViewVC logotype

Diff of /contributions/modules/views/modules/node/views_plugin_argument_validate_node.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.1 by merlinofchaos, Wed Jun 10 22:05:24 2009 UTC revision 1.1.2.2 by merlinofchaos, Thu Nov 26 00:35:16 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: views_plugin_argument_validate_node.inc,v 1.1 2008/09/03 19:21:29 merlinofchaos Exp $  // $Id: views_plugin_argument_validate_node.inc,v 1.1.2.1 2009/06/10 22:05:24 merlinofchaos Exp $
3  /**  /**
4   * @file   * @file
5   * Contains the 'node' argument validator plugin.   * Contains the 'node' argument validator plugin.
# Line 9  Line 9 
9   * Validate whether an argument is an acceptable node.   * Validate whether an argument is an acceptable node.
10   */   */
11  class views_plugin_argument_validate_node extends views_plugin_argument_validate {  class views_plugin_argument_validate_node extends views_plugin_argument_validate {
12    var $option_name = 'validate_argument_node_type';    function option_definition() {
13        $options = parent::option_definition();
14        $options['types'] = array('default' => array());
15        $options['access'] = array('default' => FALSE);
16        $options['nid_type'] = array('default' => 'nid');
17    
18    function validate_form(&$form, &$form_state) {      return $options;
19      }
20    
21      function options_form(&$form, &$form_state) {
22      $types = node_get_types();      $types = node_get_types();
23      foreach ($types as $type => $info) {      foreach ($types as $type => $info) {
24        $options[$type] = check_plain(t($info->name));        $options[$type] = check_plain(t($info->name));
25      }      }
26    
27      $arg = $this->get_argument();      $form['types'] = array(
     if (empty($arg)) {  
       $arg = array();  
     }  
   
     $form[$this->option_name] = array(  
28        '#type' => 'checkboxes',        '#type' => 'checkboxes',
       '#prefix' => '<div id="edit-options-validate-argument-node-type-wrapper">',  
       '#suffix' => '</div>',  
29        '#title' => t('Types'),        '#title' => t('Types'),
30        '#options' => $options,        '#options' => $options,
31        '#default_value' => $arg,        '#default_value' => $this->options['types'],
32        '#description' => t('If you wish to validate for specific node types, check them; if none are checked, all nodes will pass.'),        '#description' => t('If you wish to validate for specific node types, check them; if none are checked, all nodes will pass.'),
       '#process' => array('expand_checkboxes', 'views_process_dependency'),  
       '#dependency' => array('edit-options-validate-type' => array($this->id)),  
33      );      );
34    
35      $form['validate_argument_node_access'] = array(      $form['access'] = array(
36        '#type' => 'checkbox',        '#type' => 'checkbox',
37        '#title' => t('Validate user has access to the node'),        '#title' => t('Validate user has access to the node'),
38        '#default_value' => !empty($this->argument->options['validate_argument_node_access']),        '#default_value' => $this->options['access'],
       '#process' => array('views_process_dependency'),  
       '#dependency' => array('edit-options-validate-type' => array($this->id)),  
39      );      );
40    
41      $form['validate_argument_nid_type'] = array(      $form['nid_type'] = array(
42        '#type' => 'select',        '#type' => 'select',
43        '#title' => t('Argument type'),        '#title' => t('Argument type'),
44        '#options' => array(        '#options' => array(
45          'nid' => t('Node ID'),          'nid' => t('Node ID'),
46          'nids' => t('Node IDs separated by , or +'),          'nids' => t('Node IDs separated by , or +'),
47        ),        ),
48        '#default_value' => isset($this->argument->options['validate_argument_nid_type']) ? $this->argument->options['validate_argument_nid_type'] : 'nid',        '#default_value' => $this->options['nid_type'],
       '#process' => array('views_process_dependency'),  
       '#dependency' => array('edit-options-validate-type' => array($this->id)),  
49      );      );
50    }    }
51    
52    function validate_argument($argument) {    function options_submit(&$form, &$form_state, &$options) {
53      $types = array_filter($this->argument->options[$this->option_name]);      // filter trash out of the options so we don't store giant unnecessary arrays
54        $options['types'] = array_filter($options['types']);
55      }
56    
57      $type = isset($this->argument->options['validate_argument_nid_type']) ? $this->argument->options['validate_argument_nid_type'] : 'nid';    function convert_options(&$options) {
58        if (!isset($options['types']) && !empty($this->argument->options['validate_argument_node_type'])) {
59          $options['types'] = $this->argument->options['validate_argument_node_type'];
60          $options['access'] = !empty($this->argument->options['validate_argument_node_access']);
61          $options['nid_type'] = $this->argument->options['validate_argument_nid_type'];
62        }
63      }
64    
65      function validate_argument($argument) {
66        $types = $this->options['types'];
67    
68      switch ($type) {      switch ($this->options['nid_type']) {
69        case 'nid':        case 'nid':
70          if (!is_numeric($argument)) {          if (!is_numeric($argument)) {
71            return FALSE;            return FALSE;
# Line 70  class views_plugin_argument_validate_nod Line 75  class views_plugin_argument_validate_nod
75            return FALSE;            return FALSE;
76          }          }
77    
78          if (!empty($this->argument->options['validate_argument_node_access'])) {          if (!empty($this->options['access'])) {
79            if (!node_access('view', $node)) {            if (!node_access('view', $node)) {
80              return FALSE;              return FALSE;
81            }            }
# Line 88  class views_plugin_argument_validate_nod Line 93  class views_plugin_argument_validate_nod
93        case 'nids':        case 'nids':
94          $nids = new stdClass();          $nids = new stdClass();
95          $nids->value = array($argument);          $nids->value = array($argument);
96          $nids = views_break_phrase($argument, $nids);          $nids = views_nid_type($argument, $nids);
97          if ($nids->value == -1) {          if ($nids->value == -1) {
98            return FALSE;            return FALSE;
99          }          }
# Line 104  class views_plugin_argument_validate_nod Line 109  class views_plugin_argument_validate_nod
109              return FALSE;              return FALSE;
110            }            }
111    
112            if (!empty($this->argument->options['validate_argument_node_access'])) {            if (!empty($this->options['access'])) {
113              if (!node_access('view', $node)) {              if (!node_access('view', $node)) {
114                return FALSE;                return FALSE;
115              }              }

Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.1.2.2

  ViewVC Help
Powered by ViewVC 1.1.3