string.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Plugin to provide a string context
  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. 'description' => t('A context that is just a string.'),
  14. 'context' => 'ctools_context_create_string',
  15. 'keyword' => 'string',
  16. 'no ui' => FALSE,
  17. 'context name' => 'string',
  18. 'convert list' => array(
  19. 'raw' => t('Raw string'),
  20. 'html_safe' => t('HTML-safe string'),
  21. ),
  22. 'convert' => 'ctools_context_string_convert',
  23. 'placeholder form' => array(
  24. '#type' => 'textfield',
  25. '#description' => t('Enter the string for this context.'),
  26. ),
  27. );
  28. /**
  29. * It's important to remember that $conf is optional here, because contexts
  30. * are not always created from the UI.
  31. */
  32. function ctools_context_create_string($empty, $data = NULL, $conf = FALSE) {
  33. // The input is expected to be an object as created by ctools_break_phrase
  34. // which contains a group of string.
  35. $context = new ctools_context('string');
  36. $context->plugin = 'string';
  37. if ($empty) {
  38. return $context;
  39. }
  40. if ($data !== FALSE ) {
  41. $context->data = $data;
  42. $context->title = ($conf) ? check_plain($data['identifier']) : check_plain($data);
  43. return $context;
  44. }
  45. }
  46. /**
  47. * Convert a context into a string.
  48. */
  49. function ctools_context_string_convert($context, $type) {
  50. switch ($type) {
  51. case 'raw':
  52. return $context->data;
  53. case 'html_safe':
  54. return check_plain($context->data);
  55. }
  56. }