views_plugin_argument_default.inc

  1. 3.x plugins/views_plugin_argument_default.inc
  2. 2.x plugins/views_plugin_argument_default.inc

Contains the fixed argument default plugin.

File

plugins/views_plugin_argument_default.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains the fixed argument default plugin.
  5. */
  6. /**
  7. * @defgroup views_argument_default_plugins Views' argument default plugins
  8. * @{
  9. *
  10. * Allow specialized methods of filling in arguments when they aren't
  11. * provided.
  12. *
  13. * @see hook_views_plugins
  14. */
  15. /**
  16. * The fixed argument default handler; also used as the base.
  17. */
  18. class views_plugin_argument_default extends views_plugin {
  19. var $option_name = 'default_argument_fixed';
  20. /**
  21. * Initialize this plugin with the view and the argument
  22. * it is linked to.
  23. */
  24. function init(&$view, &$argument, $id = NULL) {
  25. $this->view = &$view;
  26. $this->argument = &$argument;
  27. $this->id = $id;
  28. }
  29. /**
  30. * Determine if the administrator has the privileges to use this
  31. * plugin
  32. */
  33. function access() { return TRUE; }
  34. function argument_form(&$form, &$form_state) {
  35. $form[$this->option_name] = array(
  36. '#type' => 'textfield',
  37. '#title' => t('Default argument'),
  38. '#default_value' => $this->get_argument(),
  39. '#process' => array('views_process_dependency'),
  40. '#dependency' => array(
  41. 'radio:options[default_action]' => array('default'),
  42. 'radio:options[default_argument_type]' => array($this->id)
  43. ),
  44. '#dependency_count' => 2,
  45. );
  46. // Only do this if using one simple standard form gadget
  47. $this->check_access($form);
  48. }
  49. /**
  50. * If we don't have access to the form but are showing it anyway, ensure that
  51. * the form is safe and cannot be changed from user input.
  52. */
  53. function check_access(&$form) {
  54. if (!$this->access()) {
  55. $form[$this->option_name]['#disabled'] = TRUE;
  56. $form[$this->option_name]['#value'] = $form[$this->option_name]['#default_value'];
  57. $form[$this->option_name]['#description'] .= ' <strong>' . t('Note: you do not have permission to modify this. If you change the default argument type, this setting will be lost and you will NOT be able to get it back.') . '</strong>';
  58. }
  59. }
  60. /**
  61. * Return the default argument.
  62. */
  63. function get_argument() {
  64. return isset($this->argument->options[$this->option_name]) ? $this->argument->options[$this->option_name] : '';
  65. }
  66. }
  67. /**
  68. * @}
  69. */