views_plugin_argument_default_raw.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_plugin_argument_default_raw.
  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. /**
  13. * {@inheritdoc}
  14. */
  15. public function option_definition() {
  16. $options = parent::option_definition();
  17. $options['index'] = array('default' => '');
  18. $options['use_alias'] = array('default' => FALSE, 'bool' => TRUE);
  19. return $options;
  20. }
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function options_form(&$form, &$form_state) {
  25. parent::options_form($form, $form_state);
  26. // Using range(1, 10) will create an array keyed 0-9, which allows arg() to
  27. // properly function since it is also zero-based.
  28. $form['index'] = array(
  29. '#type' => 'select',
  30. '#title' => t('Path component'),
  31. '#default_value' => $this->options['index'],
  32. '#options' => range(1, 10),
  33. '#description' => t('The numbering starts from 1, e.g. on the page admin/structure/types, the 3rd path component is "types".'),
  34. );
  35. $form['use_alias'] = array(
  36. '#type' => 'checkbox',
  37. '#title' => t('Use path alias'),
  38. '#default_value' => $this->options['use_alias'],
  39. '#description' => t('Use path alias instead of internal path.'),
  40. );
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function get_argument() {
  46. $path = NULL;
  47. if ($this->options['use_alias']) {
  48. $path = drupal_get_path_alias();
  49. }
  50. if ($arg = arg($this->options['index'], $path)) {
  51. return $arg;
  52. }
  53. }
  54. }