panels_ipe.module 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. $display = $vars['display'];
  124. $attributes = array(
  125. 'class' => 'panels-ipe-linkbar',
  126. );
  127. $type = ctools_get_content_type($pane->type);
  128. $title ='<span class = "panels-ipe-dragbar-admin-title">' . ctools_content_admin_title($type, $pane->subtype, $pane->configuration, $display->context) . '</span>';
  129. $links = theme('links', array('links' => $vars['links'], 'attributes' => $attributes));
  130. if (!empty($pane->locks['type']) && $pane->locks['type'] == 'immovable') {
  131. $links = '<div class="panels-ipe-dragbar panels-ipe-nodraghandle clearfix">' . $links .$title .'</div>';
  132. }
  133. else {
  134. $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>';
  135. }
  136. $handlebar = '<div class="panels-ipe-handlebar-wrapper panels-ipe-on">' . $links . '</div>';
  137. return $handlebar . $output;
  138. }
  139. function theme_panels_ipe_region_wrapper($vars) {
  140. return $vars['controls'] . $vars['output'];
  141. }
  142. function template_preprocess_panels_ipe_add_pane_button(&$vars) {
  143. $region_id = $vars['region_id'];
  144. $display = $vars['display'];
  145. $renderer = $vars['renderer'];
  146. $vars['links'] = '';
  147. // Add option to configure style in IPE
  148. if (user_access('administer panels styles')) {
  149. $vars['links']['style'] = array(
  150. 'title' => '<span>' . t('Region style') . '</span>',
  151. 'href' => $renderer->get_url('style-type', 'region', $region_id),
  152. 'html' => TRUE,
  153. 'attributes' => array(
  154. 'class' => array('ctools-use-modal', 'panels-ipe-hide-bar', 'style'),
  155. 'title' => t('Region style'),
  156. ),
  157. );
  158. }
  159. // Add option to add items in the IPE
  160. $vars['links']['add-pane'] = array(
  161. 'title' => '<span>' . t('Add new pane') . '</span>',
  162. 'href' => $renderer->get_url('select-content', $region_id),
  163. 'attributes' => array(
  164. 'class' => array('ctools-use-modal', 'add', 'panels-ipe-hide-bar'),
  165. 'title' => t('Add new pane'),
  166. ),
  167. 'html' => TRUE,
  168. );
  169. $context = array(
  170. 'region_id' => $region_id,
  171. 'display' => $display,
  172. 'renderer' => $renderer,
  173. );
  174. drupal_alter('panels_ipe_region_links', $vars['links'], $context);
  175. }
  176. function theme_panels_ipe_add_pane_button($vars) {
  177. $attributes = array(
  178. 'class' => array('panels-ipe-linkbar', 'inline'),
  179. );
  180. $links = theme('links', array('links' => $vars['links'], 'attributes' => $attributes));
  181. return '<div class="panels-ipe-newblock panels-ipe-on">' . $links . '</div>';
  182. }
  183. /**
  184. * @deprecated
  185. */
  186. function panels_ipe_get_cache_key($key = NULL) {
  187. return array();
  188. }
  189. /**
  190. * Add a button to the IPE toolbar.
  191. */
  192. function panels_ipe_toolbar_add_button($cache_key, $id, $button) {
  193. $buttons = &drupal_static('panels_ipe_toolbar_buttons', array());
  194. drupal_alter('panels_ipe_button', $button, $id, $cache_key);
  195. $buttons[$cache_key][$id] = $button;
  196. }
  197. /**
  198. * Implementation of hook_footer()
  199. *
  200. * Adds the IPE control container.
  201. *
  202. * @param unknown_type $main
  203. */
  204. function panels_ipe_page_alter(&$page) {
  205. $buttons = &drupal_static('panels_ipe_toolbar_buttons', array());
  206. if (empty($buttons)) {
  207. return;
  208. }
  209. $output = theme('panels_ipe_toolbar', array('buttons' => $buttons));
  210. $page['page_bottom']['panels_ipe'] = array(
  211. '#markup' => $output,
  212. );
  213. }
  214. function theme_panels_ipe_toolbar($vars) {
  215. $buttons = $vars['buttons'];
  216. ctools_include('cleanstring');
  217. $output = "<div id='panels-ipe-control-container' class='clearfix'>";
  218. foreach ($buttons as $key => $ipe_buttons) {
  219. $key = ctools_cleanstring($key);
  220. $output .= "<div id='panels-ipe-control-$key' class='panels-ipe-control'>";
  221. // Controls in this container will appear when the IPE is not on.
  222. $output .= '<div class="panels-ipe-button-container clearfix">';
  223. foreach ($ipe_buttons as $button) {
  224. $output .= is_string($button) ? $button : drupal_render($button);
  225. }
  226. $output .= '</div>';
  227. // Controls in this container will appear when the IPE is on. It is usually
  228. // filled via AJAX.
  229. $output .= '<div class="panels-ipe-form-container clearfix"></div>';
  230. $output .= '</div>';
  231. }
  232. $output .= "</div>";
  233. return $output;
  234. }