views_plugin_argument_default_raw.inc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * @file
  4. * Contains the raw value argument default plugin.
  5. */
  6. /**
  7. * Default argument plugin to use the raw value from the URL.
  8. *
  9. * @ingroup views_argument_default_plugins
  10. */
  11. class views_plugin_argument_default_raw extends views_plugin_argument_default {
  12. function option_definition() {
  13. $options = parent::option_definition();
  14. $options['index'] = array('default' => '');
  15. $options['use_alias'] = array('default' => FALSE, 'bool' => TRUE);
  16. return $options;
  17. }
  18. function options_form(&$form, &$form_state) {
  19. parent::options_form($form, $form_state);
  20. // Using range(1, 10) will create an array keyed 0-9, which allows arg() to
  21. // properly function since it is also zero-based.
  22. $form['index'] = array(
  23. '#type' => 'select',
  24. '#title' => t('Path component'),
  25. '#default_value' => $this->options['index'],
  26. '#options' => range(1, 10),
  27. '#description' => t('The numbering starts from 1, e.g. on the page admin/structure/types, the 3rd path component is "types".'),
  28. );
  29. $form['use_alias'] = array(
  30. '#type' => 'checkbox',
  31. '#title' => t('Use path alias'),
  32. '#default_value' => $this->options['use_alias'],
  33. '#description' => t('Use path alias instead of internal path.'),
  34. );
  35. }
  36. function get_argument() {
  37. $path = NULL;
  38. if ($this->options['use_alias']) {
  39. $path = drupal_get_path_alias();
  40. }
  41. if ($arg = arg($this->options['index'], $path)) {
  42. return $arg;
  43. }
  44. }
  45. }