context_reaction_theme.inc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Expose themes as context reactions.
  4. */
  5. class context_reaction_theme extends context_reaction {
  6. /**
  7. * Editor form.
  8. */
  9. function editor_form($context) {
  10. $form = $this->options_form($context);
  11. // Hide descriptions which take up too much space.
  12. unset($form['title']['#description']);
  13. unset($form['subtitle']['#description']);
  14. unset($form['class']['#description']);
  15. return $form;
  16. }
  17. /**
  18. * Submit handler for editor form.
  19. */
  20. function editor_form_submit($context, $values) {
  21. return $values;
  22. }
  23. /**
  24. * Allow admins to provide a section title, section subtitle and section class.
  25. */
  26. function options_form($context) {
  27. $values = $this->fetch_from_context($context);
  28. $form = array(
  29. '#tree' => TRUE,
  30. '#title' => t('Theme variables'),
  31. 'title' => array(
  32. '#title' => t('Section title'),
  33. '#description' => t('Provides this text as a <strong>$section_title</strong> variable for display in page.tpl.php when this context is active.'),
  34. '#type' => 'textfield',
  35. '#maxlength' => 255,
  36. '#default_value' => isset($values['title']) ? $values['title'] : '',
  37. ),
  38. 'subtitle' => array(
  39. '#title' => t('Section subtitle'),
  40. '#description' => t('Provides this text as a <strong>$section_subtitle</strong> variable for display in page.tpl.php when this context is active.'),
  41. '#type' => 'textfield',
  42. '#maxlength' => 255,
  43. '#default_value' => isset($values['subtitle']) ? $values['subtitle'] : '',
  44. ),
  45. );
  46. return $form;
  47. }
  48. /**
  49. * Set 'section_title', and 'section_subtitle' if not set
  50. */
  51. function execute(&$vars) {
  52. $classes = array();
  53. foreach ($this->get_contexts() as $k => $v) {
  54. if (!empty($v->reactions[$this->plugin]['title']) && !isset($vars['section_title'])) {
  55. $vars['section_title'] = check_plain(t($v->reactions[$this->plugin]['title']));
  56. }
  57. if (!empty($v->reactions[$this->plugin]['subtitle']) && !isset($vars['section_subtitle'])) {
  58. $vars['section_subtitle'] = check_plain(t($v->reactions[$this->plugin]['subtitle']));
  59. }
  60. }
  61. }
  62. }