/[drupal]/contributions/modules/views/handlers/views_handler_argument.inc
ViewVC logotype

Diff of /contributions/modules/views/handlers/views_handler_argument.inc

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

revision 1.7.2.5 by merlinofchaos, Mon Nov 16 20:05:39 2009 UTC revision 1.7.2.6 by merlinofchaos, Thu Nov 26 00:35:16 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: views_handler_argument.inc,v 1.7.2.4 2009/11/16 19:52:56 merlinofchaos Exp $  // $Id: views_handler_argument.inc,v 1.7.2.5 2009/11/16 20:05:39 merlinofchaos Exp $
3    
4  /**  /**
5   * @defgroup views_argument_handlers Handlers for arguments   * @defgroup views_argument_handlers Handlers for arguments
# Line 96  class views_handler_argument extends vie Line 96  class views_handler_argument extends vie
96      $options = parent::option_definition();      $options = parent::option_definition();
97    
98      $options['default_action'] = array('default' => 'ignore');      $options['default_action'] = array('default' => 'ignore');
99      $options['style_plugin'] = array('default' => 'default_summary');      $options['style_plugin'] = array('default' => 'default_summary', 'export' => 'export_style');
100      $options['style_options'] = array('default' => array());      $options['style_options'] = array('default' => array(), 'export' => FALSE);
101      $options['wildcard'] = array('default' => 'all');      $options['wildcard'] = array('default' => 'all');
102      $options['wildcard_substitution'] = array('default' => t('All'), 'translatable' => TRUE);      $options['wildcard_substitution'] = array('default' => t('All'), 'translatable' => TRUE);
103      $options['title'] = array('default' => '', 'translatable' => TRUE);      $options['title'] = array('default' => '', 'translatable' => TRUE);
104      $options['breadcrumb'] = array('default' => '', 'translatable' => TRUE);      $options['breadcrumb'] = array('default' => '', 'translatable' => TRUE);
105      $options['default_argument_type'] = array('default' => 'fixed');      $options['default_argument_type'] = array('default' => 'fixed', 'export' => 'export_plugin');
106      $options['default_argument'] = array('default' => '');      $options['default_argument_options'] = array('default' => array(), 'export' => FALSE);
107      $options['validate_type'] = array('default' => 'none');      $options['validate_type'] = array('default' => 'none', 'export' => 'export_plugin');
108        $options['validate_options'] = array('default' => array(), 'export' => FALSE);
109      $options['validate_fail'] = array('default' => 'not found');      $options['validate_fail'] = array('default' => 'not found');
110    
111      return $options;      return $options;
# Line 220  class views_handler_argument extends vie Line 221  class views_handler_argument extends vie
221    
222        // If we decide this validator is ok, add it to the list.        // If we decide this validator is ok, add it to the list.
223        if ($valid) {        if ($valid) {
224          $plugin = views_get_plugin('argument validator', $id);          $plugin = $this->get_plugin('argument validator', $id);
225          if ($plugin) {          if ($plugin) {
           $plugin->init($this->view, $this, $id);  
226            if ($plugin->access() || $this->options['validate_type'] == $id) {            if ($plugin->access() || $this->options['validate_type'] == $id) {
227              $plugin->validate_form($form, $form_state, $id);              $form['argument_validate'][$id] = array(
228                  '#type' => 'item',
229                  '#input' => TRUE, // trick it into checking input to make #process run
230                  '#process' => array('views_process_dependency'),
231                  '#dependency' => array(
232                    'edit-options-validate-type' => array($id)
233                  ),
234                );
235                $plugin->options_form($form['argument_validate'][$id], $form_state);
236              $validate_types[$id] = $info['title'];              $validate_types[$id] = $info['title'];
237            }            }
238          }          }
# Line 246  class views_handler_argument extends vie Line 254  class views_handler_argument extends vie
254      );      );
255    }    }
256    
257      function options_validate(&$form, &$form_state) {
258        if (empty($form_state['values']['options'])) {
259          return;
260        }
261    
262        // Let the plugins do validation.
263        $default_id = $form_state['values']['options']['default_argument_type'];
264        $plugin = $this->get_plugin('argument default', $default_id);
265        if ($plugin) {
266          $plugin->options_validate($form['argument_default'][$default_id], $form_state, $form_state['values']['options']['argument_default'][$default_id]);
267        }
268    
269        $validate_id = $form_state['values']['options']['validate_type'];
270        $plugin = $this->get_plugin('argument validator', $validate_id);
271        if ($plugin) {
272          $plugin->options_validate($form['argument_validate'][$default_id], $form_state, $form_state['values']['options']['argument_validate'][$validate_id]);
273        }
274    
275      }
276    
277      function options_submit(&$form, &$form_state) {
278        if (empty($form_state['values']['options'])) {
279          return;
280        }
281    
282        // Let the plugins make submit modifications if necessary.
283        $default_id = $form_state['values']['options']['default_argument_type'];
284        $plugin = $this->get_plugin('argument default', $default_id);
285        if ($plugin) {
286          $options = &$form_state['values']['options']['argument_default'][$default_id];
287          $plugin->options_submit($form['argument_default'][$default_id], $form_state, $options);
288          // Copy the now submitted options to their final resting place so they get saved.
289          $form_state['values']['options']['default_argument_options'] = $options;
290        }
291    
292        $validate_id = $form_state['values']['options']['validate_type'];
293        $plugin = $this->get_plugin('argument validator', $validate_id);
294        if ($plugin) {
295          $options = &$form_state['values']['options']['argument_default'][$validate_id];
296          $plugin->options_submit($form['argument_validate'][$default_id], $form_state, $options);
297          // Copy the now submitted options to their final resting place so they get saved.
298          $form_state['values']['options']['validate_options'] = $options;
299        }
300      }
301    
302    /**    /**
303     * Provide a list of default behaviors for this argument if the argument     * Provide a list of default behaviors for this argument if the argument
304     * is not present.     * is not present.
# Line 329  class views_handler_argument extends vie Line 382  class views_handler_argument extends vie
382        '#id' => 'edit-options-default-argument-type',        '#id' => 'edit-options-default-argument-type',
383        '#title' => t('Default argument type'),        '#title' => t('Default argument type'),
384        '#default_value' => $this->options['default_argument_type'],        '#default_value' => $this->options['default_argument_type'],
       '#process' => array('expand_radios', 'views_process_dependency'),  
       '#dependency' => array('radio:options[default_action]' => array('default')),  
385      );      );
386    
387      foreach ($plugins as $id => $info) {      foreach ($plugins as $id => $info) {
388        $plugin = views_get_plugin('argument default', $id);        if (!empty($info['no ui'])) {
389        if ($plugin) {          continue;
390          $plugin->init($this->view, $this, $id);        }
391    
392          $plugin = $this->get_plugin('argument default', $id);
393          if ($plugin) {
394          if ($plugin->access() || $this->options['default_argument_type'] == $id) {          if ($plugin->access() || $this->options['default_argument_type'] == $id) {
395              $form['argument_default'][$id] = array(
396                '#type' => 'item',
397                '#input' => TRUE, // trick it into checking input to make #process run
398                '#process' => array('views_process_dependency'),
399                '#dependency' => array(
400                  'radio:options[default_action]' => array('default'),
401                  'radio:options[default_argument_type]' => array($id)
402                ),
403                '#dependency_count' => 2,
404              );
405            $options[$id] = $info['title'];            $options[$id] = $info['title'];
406            $plugin->argument_form($form, $form_state);            $plugin->options_form($form['argument_default'][$id], $form_state);
407          }          }
408        }        }
409      }      }
# Line 442  class views_handler_argument extends vie Line 505  class views_handler_argument extends vie
505     * Get a default argument, if available.     * Get a default argument, if available.
506     */     */
507    function get_default_argument() {    function get_default_argument() {
508      $plugin = views_get_plugin('argument default', $this->options['default_argument_type']);      $plugin = $this->get_plugin('argument default');
509      if ($plugin) {      if ($plugin) {
       $plugin->init($this->view, $this);  
510        return $plugin->get_argument();        return $plugin->get_argument();
511      }      }
512    }    }
# Line 642  class views_handler_argument extends vie Line 704  class views_handler_argument extends vie
704        return $this->argument_validated = $this->validate_argument_basic($arg);        return $this->argument_validated = $this->validate_argument_basic($arg);
705      }      }
706    
707      $plugin = views_get_plugin('argument validator', $this->options['validate_type']);      $plugin = $this->get_plugin('argument validator');
708      if ($plugin) {      if ($plugin) {
       $plugin->init($this->view, $this, $this->options['validate_type']);  
709        return $this->argument_validated = $plugin->validate_argument($arg);        return $this->argument_validated = $plugin->validate_argument($arg);
710      }      }
711    
# Line 742  class views_handler_argument extends vie Line 803  class views_handler_argument extends vie
803      unset($argument);      unset($argument);
804      return $value;      return $value;
805    }    }
806    
807      /**
808       * Special handling for the style export.
809       *
810       * Arguments can have styles for the summary view. This special export
811       * handler makes sure this works properly.
812       */
813      function export_style($indent, $prefix, $storage, $option, $definition, $parents) {
814        $output = '';
815        $name = $storage[$option];
816        $options = $storage['style_options'];
817    
818        $plugin = views_get_plugin('style', $name);
819        if ($plugin) {
820          $plugin->init($this->view, $this->display, $options);
821          // Write which plugin to use.
822          $output .= $indent . $prefix . "['$option'] = '$name';\n";
823    
824          // Pass off to the plugin to export itself.
825          $output .= $plugin->export_options($indent, $prefix . "['style_options']");
826        }
827    
828        return $output;
829      }
830    
831      /**
832       * Special handling for the style export.
833       *
834       * Arguments can have styles for the summary view. This special export
835       * handler makes sure this works properly.
836       */
837      function export_plugin($indent, $prefix, $storage, $option, $definition, $parents) {
838        $output = '';
839        if ($option == 'default_argument_type') {
840          $type = 'argument default';
841          $option_name = 'default_argument_options';
842        }
843        else {
844          $type = 'argument validator';
845          $option_name = 'validate_options';
846        }
847        $plugin = $this->get_plugin($type);
848        $name = $this->options[$option];
849    
850        if ($plugin) {
851          // Write which plugin to use.
852          $output .= $indent . $prefix . "['$option'] = '$name';\n";
853    
854          // Pass off to the plugin to export itself.
855          $output .= $plugin->export_options($indent, $prefix . "['$option_name']");
856        }
857    
858        return $output;
859      }
860    
861      /**
862       * Get the display or row plugin, if it exists.
863       */
864      function get_plugin($type = 'argument default', $name = NULL) {
865        $options = array();
866        switch ($type) {
867          case 'argument default':
868            $plugin_name = 'default_argument_type';
869            $options_name = 'default_argument_options';
870            break;
871          case 'argument validator':
872            $plugin_name = 'validate_type';
873            $options_name = 'validate_options';
874        }
875    
876        if (!$name) {
877          $name = $this->options[$plugin_name];
878        }
879    
880        // we only fetch the options if we're fetching the plugin actually
881        // in use.
882        if ($name == $this->options[$plugin_name]) {
883          $options = $this->options[$options_name];
884        }
885    
886        $plugin = views_get_plugin($type, $name);
887        if ($plugin) {
888          $plugin->init($this->view, $this, $options);
889          return $plugin;
890        }
891      }
892  }  }
893    
894  /**  /**

Legend:
Removed from v.1.7.2.5  
changed lines
  Added in v.1.7.2.6

  ViewVC Help
Powered by ViewVC 1.1.3