panels_ipe.module 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. /**
  3. * @file
  4. */
  5. /**
  6. * Implementation of hook_ctools_plugin_directory().
  7. */
  8. function panels_ipe_ctools_plugin_directory($module, $plugin) {
  9. if ($module == 'panels' && $plugin == 'display_renderers') {
  10. return 'plugins/' . $plugin;
  11. }
  12. }
  13. /**
  14. * Implementation of hook_ctools_plugin_api().
  15. *
  16. * Inform CTools about version information for various plugins implemented by
  17. * Panels.
  18. *
  19. * @param string $owner
  20. * The system name of the module owning the API about which information is
  21. * being requested.
  22. * @param string $api
  23. * The name of the API about which information is being requested.
  24. */
  25. function panels_ipe_ctools_plugin_api($owner, $api) {
  26. if ($owner == 'panels' && $api == 'pipelines') {
  27. return array(
  28. 'version' => 1,
  29. 'path' => drupal_get_path('module', 'panels_ipe') . '/includes',
  30. );
  31. }
  32. }
  33. /**
  34. * Implementation of hook_theme().
  35. */
  36. function panels_ipe_theme() {
  37. return array(
  38. 'panels_ipe_pane_wrapper' => array(
  39. 'variables' => array('output' => NULL, 'pane' => NULL, 'display' => NULL, 'renderer' => NULL),
  40. ),
  41. 'panels_ipe_region_wrapper' => array(
  42. 'variables' => array('output' => NULL, 'region_id' => NULL, 'display' => NULL, 'controls' => NULL, 'renderer' => NULL),
  43. ),
  44. 'panels_ipe_add_pane_button' => array(
  45. 'variables' => array('region_id' => NULL, 'display' => NULL, 'renderer' => NULL),
  46. ),
  47. 'panels_ipe_placeholder_pane' => array(
  48. 'variables' => array('region_id' => NULL, 'region_title' => NULL),
  49. ),
  50. 'panels_ipe_dnd_form_container' => array(
  51. 'variables' => array('link' => NULL, 'cache_key' => NULL, 'display' => NULL),
  52. ),
  53. 'panels_ipe_toolbar' => array(
  54. 'variables' => array('buttons' => NULL),
  55. ),
  56. );
  57. }
  58. /**
  59. * Theme the 'placeholder' pane, which is shown on an active IPE when no panes
  60. * live in that region.
  61. *
  62. * @param string $region_id
  63. * @param string $region_title
  64. */
  65. function theme_panels_ipe_placeholder_pane($vars) {
  66. $region_id = $vars['region_id'];
  67. $region_title = $vars['region_title'];
  68. $output = '<div class="panels-ipe-placeholder-content">';
  69. $output .= "<h3>$region_title</h3>";
  70. $output .= '</div>';
  71. return $output;
  72. }
  73. function template_preprocess_panels_ipe_pane_wrapper(&$vars) {
  74. $pane = $vars['pane'];
  75. $display = $vars['display'];
  76. $renderer = $vars['renderer'];
  77. $content_type = ctools_get_content_type($pane->type);
  78. $subtype = ctools_content_get_subtype($content_type, $pane->subtype);
  79. $vars['links'] = array();
  80. if (ctools_content_editable($content_type, $subtype, $pane->configuration)) {
  81. $vars['links']['edit'] = array(
  82. 'title' => isset($content_type['edit text']) ? '<span>' . $content_type['edit text'] . '</span>' : '<span>' . t('Settings') . '</span>',
  83. 'href' => $renderer->get_url('edit-pane', $pane->pid),
  84. 'html' => TRUE,
  85. 'attributes' => array(
  86. 'class' => array('ctools-use-modal', 'panels-ipe-hide-bar'),
  87. 'title' => isset($content_type['edit text']) ? $content_type['edit text'] : t('Settings'),
  88. // 'id' => "pane-edit-panel-pane-$pane->pid",.
  89. ),
  90. );
  91. }
  92. // Add option to configure style in IPE.
  93. if (user_access('administer panels pane styles')) {
  94. $vars['links']['style'] = array(
  95. 'title' => '<span>' . t('Style') . '</span>',
  96. 'href' => $renderer->get_url('style-type', 'pane', $pane->pid),
  97. 'html' => TRUE,
  98. 'attributes' => array(
  99. 'class' => array('ctools-use-modal', 'panels-ipe-hide-bar'),
  100. 'title' => t('Style'),
  101. ),
  102. );
  103. }
  104. // Add option to configure CSS.
  105. if (user_access('administer advanced pane settings')) {
  106. $vars['links']['css'] = array(
  107. 'title' => '<span>' . t('CSS') . '</span>',
  108. 'href' => $renderer->get_url('pane-css', $pane->pid),
  109. 'html' => TRUE,
  110. 'attributes' => array(
  111. 'class' => array('ctools-use-modal', 'panels-ipe-hide-bar'),
  112. 'title' => t('CSS'),
  113. ),
  114. );
  115. }
  116. // Deleting is managed entirely in the js; this is just an attachment point
  117. // for it.
  118. $vars['links']['delete'] = array(
  119. 'title' => '<span>' . t('Delete') . '</span>',
  120. 'href' => '#',
  121. 'html' => TRUE,
  122. 'attributes' => array(
  123. 'class' => 'pane-delete',
  124. 'id' => "pane-delete-panel-pane-$pane->pid",
  125. 'title' => t('Delete'),
  126. ),
  127. );
  128. $context = array(
  129. 'pane' => $pane,
  130. 'display' => $display,
  131. 'renderer' => $renderer,
  132. );
  133. drupal_alter('panels_ipe_pane_links', $vars['links'], $context);
  134. }
  135. function theme_panels_ipe_pane_wrapper($vars) {
  136. $output = $vars['output'];
  137. $pane = $vars['pane'];
  138. $display = $vars['display'];
  139. $attributes = array(
  140. 'class' => 'panels-ipe-linkbar',
  141. );
  142. $type = ctools_get_content_type($pane->type);
  143. $title = '<span class = "panels-ipe-dragbar-admin-title">' . ctools_content_admin_title($type, $pane->subtype, $pane->configuration, $display->context) . '</span>';
  144. $links = theme('links', array('links' => $vars['links'], 'attributes' => $attributes));
  145. if (!empty($pane->locks['type']) && $pane->locks['type'] == 'immovable') {
  146. $links = '<div class="panels-ipe-dragbar panels-ipe-nodraghandle clearfix">' . $links . $title . '</div>';
  147. }
  148. else {
  149. $links = '<div class="panels-ipe-dragbar panels-ipe-draghandle clearfix">' . $links . $title . '<span class="panels-ipe-draghandle-icon"><span class="panels-ipe-draghandle-icon-inner"></span></span></div>';
  150. }
  151. $handlebar = '<div class="panels-ipe-handlebar-wrapper panels-ipe-on">' . $links . '</div>';
  152. return $handlebar . $output;
  153. }
  154. function theme_panels_ipe_region_wrapper($vars) {
  155. return $vars['controls'] . $vars['output'];
  156. }
  157. function template_preprocess_panels_ipe_add_pane_button(&$vars) {
  158. $region_id = $vars['region_id'];
  159. $display = $vars['display'];
  160. $renderer = $vars['renderer'];
  161. $vars['links'] = array();
  162. // Add option to configure style in IPE.
  163. if (user_access('administer panels region styles')) {
  164. $vars['links']['style'] = array(
  165. 'title' => '<span>' . t('Region style') . '</span>',
  166. 'href' => $renderer->get_url('style-type', 'region', $region_id),
  167. 'html' => TRUE,
  168. 'attributes' => array(
  169. 'class' => array('ctools-use-modal', 'panels-ipe-hide-bar', 'style'),
  170. 'title' => t('Region style'),
  171. ),
  172. );
  173. }
  174. // Add option to add items in the IPE.
  175. $vars['links']['add-pane'] = array(
  176. 'title' => '<span>' . t('Add new pane') . '</span>',
  177. 'href' => $renderer->get_url('select-content', $region_id),
  178. 'attributes' => array(
  179. 'class' => array('ctools-use-modal', 'add', 'panels-ipe-hide-bar'),
  180. 'title' => t('Add new pane'),
  181. ),
  182. 'html' => TRUE,
  183. );
  184. $context = array(
  185. 'region_id' => $region_id,
  186. 'display' => $display,
  187. 'renderer' => $renderer,
  188. );
  189. drupal_alter('panels_ipe_region_links', $vars['links'], $context);
  190. }
  191. function theme_panels_ipe_add_pane_button($vars) {
  192. $attributes = array(
  193. 'class' => array('panels-ipe-linkbar', 'inline'),
  194. );
  195. $links = theme('links', array('links' => $vars['links'], 'attributes' => $attributes));
  196. return '<div class="panels-ipe-newblock panels-ipe-on">' . $links . '</div>';
  197. }
  198. /**
  199. * @deprecated
  200. */
  201. function panels_ipe_get_cache_key($key = NULL) {
  202. return array();
  203. }
  204. /**
  205. * Add a button to the IPE toolbar.
  206. */
  207. function panels_ipe_toolbar_add_button($cache_key, $id, $button) {
  208. $buttons = &drupal_static('panels_ipe_toolbar_buttons', array());
  209. drupal_alter('panels_ipe_button', $button, $id, $cache_key);
  210. $buttons[$cache_key][$id] = $button;
  211. }
  212. /**
  213. * Implementation of hook_footer().
  214. *
  215. * Adds the IPE control container.
  216. *
  217. * @param unknown_type $main
  218. */
  219. function panels_ipe_page_alter(&$page) {
  220. $buttons = &drupal_static('panels_ipe_toolbar_buttons', array());
  221. if (empty($buttons)) {
  222. return;
  223. }
  224. $output = theme('panels_ipe_toolbar', array('buttons' => $buttons));
  225. $page['page_bottom']['panels_ipe'] = array(
  226. '#markup' => $output,
  227. );
  228. }
  229. function theme_panels_ipe_toolbar($vars) {
  230. $buttons = $vars['buttons'];
  231. ctools_include('cleanstring');
  232. $output = "<div id='panels-ipe-control-container' class='clearfix'>";
  233. foreach ($buttons as $key => $ipe_buttons) {
  234. $key = ctools_cleanstring($key);
  235. $output .= "<div id='panels-ipe-control-$key' class='panels-ipe-control'>";
  236. // Controls in this container will appear when the IPE is not on.
  237. $output .= '<div class="panels-ipe-button-container clearfix">';
  238. foreach ($ipe_buttons as $button) {
  239. $output .= is_string($button) ? $button : drupal_render($button);
  240. }
  241. $output .= '</div>';
  242. // Controls in this container will appear when the IPE is on. It is usually
  243. // filled via AJAX.
  244. $output .= '<div class="panels-ipe-form-container clearfix"></div>';
  245. $output .= '</div>';
  246. }
  247. $output .= "</div>";
  248. return $output;
  249. }