panels_ipe.module 7.8 KB

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