string.inc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Plugin to provide an argument handler for a raw string
  6. */
  7. /**
  8. * Plugins are described by creating a $plugin array which will be used
  9. * by the system that includes this file.
  10. */
  11. $plugin = array(
  12. 'title' => t("String"),
  13. // keyword to use for %substitution
  14. 'keyword' => 'string',
  15. 'description' => t('A string is a minimal context that simply holds a string that can be used for some other purpose.'),
  16. 'settings form' => 'ctools_string_settings_form',
  17. 'context' => 'ctools_string_context',
  18. 'placeholder form' => array(
  19. '#type' => 'textfield',
  20. '#description' => t('Enter a value for this argument'),
  21. ),
  22. 'path placeholder' => 'ctools_string_path_placeholder', // This is in pagemanager.
  23. );
  24. /**
  25. * Discover if this argument gives us the term we crave.
  26. */
  27. function ctools_string_context($arg = NULL, $conf = NULL, $empty = FALSE) {
  28. // If unset it wants a generic, unfilled context.
  29. if ($empty) {
  30. return ctools_context_create_empty('string');
  31. }
  32. $context = ctools_context_create('string', $arg);
  33. $context->original_argument = $arg;
  34. return $context;
  35. }
  36. /**
  37. * Settings form for the argument
  38. */
  39. function ctools_string_settings_form(&$form, &$form_state, $conf) {
  40. $form['settings']['use_tail'] = array(
  41. '#title' => t('Get all arguments after this one'),
  42. '#type' => 'checkbox',
  43. '#default_value' => !empty($conf['use_tail']),
  44. '#description' => t('If checked, this string will include all arguments. For example, if the path is "path/%" and the user visits "path/foo/bar", if this is not checked the string will be "foo". If it is checked the string will be "foo/bar".'),
  45. );
  46. // return $form;
  47. }
  48. /**
  49. * Switch the placeholder based upon user settings.
  50. */
  51. function ctools_string_path_placeholder($argument) {
  52. if (empty($argument['settings']['use_tail'])) {
  53. return '%pm_arg';
  54. }
  55. else {
  56. return '%pm_arg_tail';
  57. }
  58. }