string.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @file
  4. * Plugin to provide an argument handler for a raw string.
  5. */
  6. /**
  7. * Plugins are described by creating a $plugin array which will be used
  8. * by the system that includes this file.
  9. */
  10. $plugin = array(
  11. 'title' => t("String"),
  12. // Keyword to use for %substitution.
  13. 'keyword' => 'string',
  14. 'description' => t('A string is a minimal context that simply holds a string that can be used for some other purpose.'),
  15. 'settings form' => 'ctools_string_settings_form',
  16. 'context' => 'ctools_string_context',
  17. 'placeholder form' => array(
  18. '#type' => 'textfield',
  19. '#description' => t('Enter a value for this argument'),
  20. ),
  21. // This is in pagemanager.
  22. 'path placeholder' => 'ctools_string_path_placeholder',
  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. }
  47. /**
  48. * Switch the placeholder based upon user settings.
  49. */
  50. function ctools_string_path_placeholder($argument) {
  51. if (empty($argument['settings']['use_tail'])) {
  52. return '%pm_arg';
  53. }
  54. else {
  55. return '%pm_arg_tail';
  56. }
  57. }