context_reaction_block.theme.inc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Block form.
  4. */
  5. function theme_context_block_form($vars) {
  6. $row = array(
  7. array('data' => drupal_render($vars['form']['blocks']), 'class' => array('blocks')),
  8. array('data' => drupal_render($vars['form']['selector']) . drupal_render($vars['form']['block']['help']), 'class' => array('selector')),
  9. );
  10. $output = drupal_render_children($vars['form']);
  11. $table = array(
  12. 'rows' => array($row),
  13. 'attributes' => array('id' => 'context-blockform'),
  14. );
  15. $output .= theme('table', $table);
  16. return $output;
  17. }
  18. /**
  19. * Generates the AJAX enabled block administration portion of the context_ui admin form.
  20. */
  21. function theme_context_block_regions_form($vars) {
  22. $form = $vars['form'];
  23. // Add draggable weights
  24. drupal_add_js('misc/tableheader.js');
  25. drupal_add_js(drupal_get_path('module', 'context') . '/plugins/context_reaction_block.js');
  26. drupal_add_css(drupal_get_path('module', 'context') . '/plugins/context_reaction_block.css');
  27. $output = '';
  28. foreach (element_children($form) as $region) {
  29. $attr = array(
  30. 'id' => "context-blockform-region-{$region}",
  31. 'class' => array("context-blockform-region"),
  32. );
  33. drupal_add_tabledrag($attr['id'], 'order', 'sibling', 'tabledrag-hide', NULL, NULL, FALSE);
  34. $rows = array();
  35. foreach (element_children($form[$region]) as $id) {
  36. $form[$region][$id]['weight']['#attributes'] = array('class' => array('tabledrag-hide'));
  37. $label = $form[$region][$id]['#value'];
  38. $remove = l(t('X'), $_GET['q'], array('fragment' => 'remove', 'attributes' => array('class' => array('remove'))));
  39. $rows[] = array(
  40. 'data' => array($label, drupal_render($form[$region][$id]['weight']), $remove),
  41. 'class' => array('draggable'),
  42. 'id' => $id,
  43. );
  44. }
  45. $output .= "<div class='label context-blockform-regionlabel-{$region}'>";
  46. $output .= l(t('+') . ' ' . t('Add'), $_GET['q'], array('fragment' => $region, 'attributes' => array('class' => array('add-block'))));
  47. $output .= $form[$region]['#title'];
  48. $output .= '</div>';
  49. $output .= theme('table', array('rows' => $rows, 'attributes' => $attr));
  50. }
  51. return $output;
  52. }
  53. /**
  54. * Use placeholder content for script tags that need to be replaced.
  55. */
  56. function theme_context_block_script_placeholder($vars) {
  57. $text = $vars['text'];
  58. $message = t('Please reload the page to view this block.');
  59. return "<div class='script-placeholder'><strong>{$text}</strong><div class='description'>{$message}</div></div>";
  60. }
  61. /**
  62. * Preprocessor for theme('context_block_browser').
  63. */
  64. function template_preprocess_context_block_browser(&$vars) {
  65. $categories = array(
  66. '#type' => 'select',
  67. '#options' => array(0 => '<' . t('All Categories') . '>'),
  68. '#attributes' => array('class' => array('context-block-browser-categories')),
  69. '#value' => 0,
  70. '#size' => 1,
  71. '#id' => '',
  72. '#name' => '',
  73. '#parents' => array(''),
  74. '#multiple' => FALSE,
  75. '#required' => FALSE,
  76. );
  77. $blocks = array();
  78. // Group blocks by module.
  79. foreach ($vars['blocks'] as $block) {
  80. $group = isset($block->context_group) ? $block->context_group : $block->module;
  81. // Normalize the $group, borrowed from drupal_html_id
  82. $group = strtr(drupal_strtolower($group), array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
  83. if (!isset($categories[$group])) {
  84. $info = system_get_info('module', $block->module);
  85. $title = isset($block->context_group) ? $block->context_group : (!empty($info['name']) ? $info['name'] : $block->module);
  86. $categories['#options'][$group] = $title;
  87. }
  88. $blocks[$group][$block->bid] = $block; // Don't call theme('context_block_browser_item') to allow others to alter.
  89. }
  90. //add help text to tell people how to use the block browser
  91. $help_text = array(
  92. '#prefix' => '<div class="context_ui-help-text">',
  93. '#markup' => t('To add a block to the current region, simply click on the block. You may use the category filter to filter by block type or the search filter to find the block that you wish to add.'),
  94. '#suffix' => '</div>',
  95. );
  96. $filter_label = array(
  97. '#prefix' => '<div class="filter-label">',
  98. '#markup' => t('Search filter'),
  99. '#suffix' => '</div>',
  100. );
  101. $vars['categories'] = $categories; // Don't call theme('select') here to allow further preprocesses to alter the element.
  102. $vars['blocks'] = $blocks;
  103. $vars['help_text'] = $help_text;
  104. $vars['filter_label'] = $filter_label;
  105. }
  106. /**
  107. * Preprocessor for theme('context_block_browser_item').
  108. */
  109. function template_preprocess_context_block_browser_item(&$vars) {
  110. $vars['bid'] = $vars['block']->bid;
  111. $vars['info'] = check_plain($vars['block']->info);
  112. }
  113. /**
  114. * Theme wrapper for editable blocks.
  115. *
  116. * @ingroup themeable
  117. */
  118. function theme_context_block_edit_wrap($vars) {
  119. $block = $vars['element']['#block'];
  120. return $vars['element']['#children'] . "<a id='context-block-{$block->module}-{$block->delta}' class='context-block editable edit-{$block->context}'></a>";
  121. }