common.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <?php
  2. /**
  3. * @file
  4. * Functions used by more than one panels client module.
  5. */
  6. /**
  7. * Class definition for the allowed layouts governing structure.
  8. *
  9. * @ingroup mainapi
  10. *
  11. * This class is designed to handle panels allowed layouts data from start to finish, and sees
  12. * action at two times:\n
  13. * - When a client module wants to generate a form allowing an admin to create or edit a set
  14. * of allowed layouts. In this case, either a new panels_allowed_layouts object is created
  15. * or one is retrieved from storage and panels_allowed_layouts::set_allowed() is called to
  16. * generate the allowed layouts form. \n
  17. * - When a client module is calling panels_edit_layout(), a saved instantiation of this object
  18. * can be called up and passed in to the fourth parameter, and only the allowed layouts saved
  19. * in that object will be displayed on the form. \n
  20. * Because the panels API does not impose a data structure on the allowed_layouts data, client
  21. * modules can create as many of these objects as they want, and organize them around any concept:
  22. * node types, date published, author roles...anything.
  23. *
  24. * To call the settings form, instantiate this class - or, if your client module's needs are
  25. * heavy-duty, extend this class and instantiate your subclass - assign values to any relevant
  26. * desired members, and call panels_allowed_layouts::set_allowed(). See the documentation on
  27. * that method for a sample implementation.
  28. *
  29. * Note that when unserializing saved tokens of this class, you must
  30. * run panels_load_include('common') before unserializing in order to ensure
  31. * that the object is properly loaded.
  32. *
  33. * Client modules extending this class should implement a save() method and use it for
  34. * their custom data storage routine. You'll need to rewrite other class methods if
  35. * you choose to go another route.
  36. *
  37. * @see panels_edit_layout()
  38. * @see _panels_edit_layout()
  39. */
  40. class panels_allowed_layouts {
  41. /**
  42. * Specifies whether newly-added layouts (as in, new .inc files) should be automatically
  43. * allowed (TRUE) or disallowed (FALSE) for $this. Defaults to TRUE, which is more
  44. * permissive but less of an administrative hassle if/when you add new layouts. Note
  45. * that this parameter will be derived from $allowed_layouts if a value is passed in.
  46. */
  47. var $allow_new = TRUE;
  48. /**
  49. * Optional member. If provided, the Panels API will generate a drupal variable using
  50. * variable_set($module_name . 'allowed_layouts', serialize($this)), thereby handling the
  51. * storage of this object entirely within the Panels API. This object will be
  52. * called and rebuilt by panels_edit_layout() if the same $module_name string is passed in
  53. * for the $allowed_types parameter. \n
  54. * This is primarily intended for convenience - client modules doing heavy-duty implementations
  55. * of the Panels API will probably want to create their own storage method.
  56. *
  57. * @see panels_edit_layout()
  58. */
  59. var $module_name = NULL;
  60. /**
  61. * An associative array of all available layouts, keyed by layout name (as defined
  62. * in the corresponding layout plugin definition), with value = 1 if the layout is
  63. * allowed, and value = 0 if the layout is not allowed.
  64. * Calling array_filter(panels_allowed_layouts::$allowed_layout_settings) will return an associative array
  65. * containing only the allowed layouts, and wrapping that in array_keys() will
  66. * return an indexed version of that array.
  67. */
  68. var $allowed_layout_settings = array();
  69. /**
  70. * Hack-imitation of D6's $form_state. Used by the panels_common_set_allowed_types()
  71. * form to indicate whether the returned value is in its 'render', 'failed-validate',
  72. * or 'submit' stage.
  73. */
  74. var $form_state;
  75. /**
  76. * Constructor function; loads the $allowed_layout_settings array with initial values according
  77. * to $start_allowed.
  78. *
  79. * @param bool $start_allowed
  80. * $start_allowed determines whether all available layouts will be marked
  81. * as allowed or not allowed on the initial call to panels_allowed_layouts::set_allowed()
  82. */
  83. function __construct($start_allowed = TRUE) {
  84. // TODO would be nice if there was a way to just fetch the names easily.
  85. foreach ($this->list_layouts() as $layout_name) {
  86. $this->allowed_layout_settings[$layout_name] = $start_allowed ? 1 : 0;
  87. }
  88. }
  89. /**
  90. * Manage panels_common_set_allowed_layouts(), the FAPI code for selecting allowed layouts.
  91. *
  92. * MAKE SURE to set panels_allowed_layouts::allow_new before calling this method. If you want the panels API
  93. * to handle saving these allowed layout settings, panels_allowed_layouts::module_name must also be set.
  94. *
  95. * Below is a sample implementation; refer to the rest of the class documentation to understand all the
  96. * specific pieces. Values that are intended to be replaced are wrapped with <>.
  97. *
  98. * \n @code
  99. * function docdemo_allowed_layouts() {
  100. * ctools_include('common', 'panels');
  101. * if (!is_a($allowed_layouts = unserialize(variable_get('panels_common_allowed_layouts', serialize(''))), 'panels_allowed_layouts')) {
  102. * $allowed_layouts = new panels_allowed_layouts();
  103. * $allowed_layouts->allow_new = TRUE;
  104. * $allowed_layouts->module_name = '<client_module_name>';
  105. * }
  106. * $result = $allowed_layouts->set_allowed('<Desired client module form title>');
  107. * if (in_array($allowed_layouts->form_state, array('failed-validate', 'render'))) {
  108. * return $result;
  109. * }
  110. * elseif ($allowed_layouts->form_state == 'submit') {
  111. * drupal_goto('</path/to/desired/redirect>');
  112. * }
  113. * }
  114. *
  115. * @endcode \n
  116. *
  117. * If $allowed_layouts->form_state == 'failed-validate' || 'render', then you'll need to return
  118. * $result as it contains the structured form HTML generated by drupal_render_form() and is ready
  119. * to be passed through index.php's call to theme('page', ...).
  120. *
  121. * However, if $allowed_layouts->form_state == 'submit', then the form has been submitted and we should
  122. * react. It's really up to your client module how you handle the rest; panels_allowed_layouts::save() (or
  123. * panels_allowed_layouts::api_save(), if that's the route you're going) will have already been called,
  124. * so if those methods handle your save routine, then all there is left to do is handle redirects, if you
  125. * want. The current implementation of the allowed layouts form currently never redirects, so it's up to
  126. * you to control where the user ends up next.
  127. *
  128. * @param string $title
  129. * Used to set the title of the allowed layouts form. If no value is given, defaults to
  130. * 'Panels: Allowed Layouts'.
  131. *
  132. * @return mixed $result
  133. * - On the first passthrough when the form is being rendered, $result is the form's structured
  134. * HTML, ready to be pushed to the screen with a call to theme('page', ...).
  135. * - A successful second passthrough indicates a successful submit, and
  136. * $result === panels_allowed_layouts::allowed_layout_settings. Returning it is simply for convenience.
  137. */
  138. function set_allowed($title = 'Panels: Allowed Layouts') {
  139. $this->sync_with_available();
  140. $form_id = 'panels_common_set_allowed_layouts';
  141. // TODO switch to drupal_build_form(); need to pass by ref.
  142. $form = drupal_retrieve_form($form_id, $this, $title);
  143. if ($result = drupal_process_form($form_id, $form)) {
  144. // Successful submit.
  145. $this->form_state = 'submit';
  146. return $result;
  147. }
  148. $this->form_state = isset($_POST['op']) ? 'failed-validate' : 'render';
  149. $result = drupal_render_form($form_id, $form);
  150. return $result;
  151. }
  152. /**
  153. * Checks for newly-added layouts and deleted layouts. If any are found, updates panels_allowed_layouts::allowed_layout_settings;
  154. * new additions are made according to panels_allowed_layouts::allow_new, while deletions are unset().
  155. *
  156. * Note that any changes made by this function are not saved in any permanent location.
  157. */
  158. function sync_with_available() {
  159. $layouts = $this->list_layouts();
  160. foreach (array_diff($layouts, array_keys($this->allowed_layout_settings)) as $new_layout) {
  161. $this->allowed_layout_settings[$new_layout] = $this->allow_new ? 1 : 0;
  162. }
  163. foreach (array_diff(array_keys($this->allowed_layout_settings), $layouts) as $deleted_layout) {
  164. unset($this->allowed_layout_settings[$deleted_layout]);
  165. }
  166. }
  167. /**
  168. * Use panels_allowed_layouts::module_name to generate a variable for variable_set(), in which
  169. * a serialized version of $this will be stored.
  170. *
  171. * Does nothing if panels_allowed_layouts::module_name is not set.
  172. *
  173. * IMPORTANT NOTE: if you use variable_get() in a custom client module save() method, you MUST
  174. * wrap $this in serialize(), then unserialize() what you get from variable_get(). Failure to
  175. * do so will result in an incomplete object. The following code will work:
  176. * @code
  177. * $allowed_layouts = unserialize(variable_get('your_variable_name', serialize(''));
  178. * @endcode
  179. *
  180. * If you don't serialize the second parameter of variable_get() and the variable name you provide
  181. * can't be found, an E_STRICT warning will be generated for trying to unserialize an entity
  182. * that has not been serialized.
  183. */
  184. function save() {
  185. if (!is_null($this->module_name)) {
  186. variable_set($this->module_name . "_allowed_layouts", serialize($this));
  187. }
  188. }
  189. /**
  190. * Snag a list of the current layouts for internal use.
  191. *
  192. * Data is not saved in a class member in order to ensure that it's
  193. * fresh.
  194. *
  195. * @return array $layouts
  196. * An indexed array of the system names for all currently available layouts.
  197. */
  198. function list_layouts() {
  199. static $layouts = array();
  200. if (empty($layouts)) {
  201. ctools_include('plugins', 'panels');
  202. $layouts = array_keys(panels_get_layouts());
  203. }
  204. return $layouts;
  205. }
  206. }
  207. /**
  208. * A common settings page for Panels modules, because this code is relevant to
  209. * any modules that don't already have special requirements.
  210. */
  211. function panels_common_settings($form, &$form_state, $module_name = 'panels_common') {
  212. ctools_include('plugins', 'panels');
  213. ctools_include('content');
  214. $content_types = ctools_get_content_types();
  215. $skip = FALSE;
  216. $default_types = variable_get($module_name . '_default', NULL);
  217. if (!isset($default_types)) {
  218. $default_types = array('other' => TRUE);
  219. $skip = TRUE;
  220. }
  221. foreach ($content_types as $id => $info) {
  222. if (empty($info['single'])) {
  223. $default_options[$id] = t('New @s', array('@s' => $info['title']));
  224. if ($skip) {
  225. $default_types[$id] = TRUE;
  226. }
  227. }
  228. }
  229. $default_options['other'] = t('New content of other types');
  230. $form['additional_settings'] = array(
  231. '#type' => 'vertical_tabs',
  232. );
  233. $form['common'] = array(
  234. '#type' => 'fieldset',
  235. '#title' => t('New content behavior'),
  236. '#group' => 'additional_settings',
  237. '#weight' => -10,
  238. );
  239. $form['common']['panels_common_default'] = array(
  240. '#type' => 'checkboxes',
  241. '#description' => t('Select the default behavior of new content added to the system. If checked, new content will automatically be immediately available to be added to Panels pages. If not checked, new content will not be available until specifically allowed here.'),
  242. '#options' => $default_options,
  243. '#default_value' => array_keys(array_filter($default_types)),
  244. );
  245. $form_state['skip'] = $skip;
  246. if ($skip) {
  247. $form['markup'] = array('#value' => t('<p>Click Submit to be presented with a complete list of available content types set to the defaults you selected.</p>'));
  248. }
  249. else {
  250. // Rebuild the entire list, setting appropriately from defaults. Give
  251. // each type its own checkboxes set unless it's 'single' in which
  252. // case it can go into our fake other set.
  253. $available_content_types = ctools_content_get_all_types();
  254. $allowed_content_types = variable_get($module_name . '_allowed_types', array());
  255. foreach ($available_content_types as $id => $types) {
  256. foreach ($types as $type => $info) {
  257. $key = $id . '-' . $type;
  258. $checkboxes = empty($content_types[$id]['single']) ? $id : 'other';
  259. $options[$checkboxes][$key] = $info['title'];
  260. if (!isset($allowed_content_types[$key])) {
  261. $allowed[$checkboxes][$key] = isset($default_types[$id]) ? $default_types[$id] : $default_types['other'];
  262. }
  263. else {
  264. $allowed[$checkboxes][$key] = $allowed_content_types[$key];
  265. }
  266. }
  267. }
  268. $form['content_types'] = array(
  269. '#tree' => TRUE,
  270. );
  271. // Cheat a bit.
  272. $content_types['other'] = array('title' => t('Other'), 'weight' => 10);
  273. foreach ($content_types as $id => $info) {
  274. if (isset($allowed[$id])) {
  275. $form['content_types'][$id] = array(
  276. '#type' => 'fieldset',
  277. '#group' => 'additional_settings',
  278. '#title' => t('Allowed @s content', array('@s' => $info['title'])),
  279. );
  280. $form['content_types'][$id]['options'] = array(
  281. '#prefix' => '<div class="panels-page-type-container">',
  282. '#suffix' => '</div>',
  283. '#type' => 'checkboxes',
  284. '#options' => $options[$id],
  285. '#default_value' => array_keys(array_filter($allowed[$id])),
  286. '#checkall' => TRUE,
  287. );
  288. }
  289. }
  290. }
  291. // Layout selection.
  292. panels_common_allowed_layouts_form($form, $form_state, $module_name);
  293. $form['allowed'] = array(
  294. '#type' => 'value',
  295. '#value' => isset($allowed) ? array_keys($allowed) : array(),
  296. );
  297. $form['module_name'] = array(
  298. '#type' => 'value',
  299. '#value' => $module_name,
  300. );
  301. $form['submit'] = array(
  302. '#type' => 'submit',
  303. '#value' => t('Save'),
  304. );
  305. ctools_add_css('panels_page', 'panels');
  306. return $form;
  307. }
  308. /**
  309. * Submit hook for panels_common_settings.
  310. */
  311. function panels_common_settings_validate($form, &$form_state) {
  312. panels_common_allowed_layouts_form_validate($form, $form_state);
  313. }
  314. /**
  315. * Submit hook for panels_common_settings.
  316. */
  317. function panels_common_settings_submit($form, &$form_state) {
  318. panels_common_allowed_layouts_form_submit($form, $form_state);
  319. $module_name = $form_state['values']['module_name'];
  320. variable_set($module_name . '_default', $form_state['values']['panels_common_default']);
  321. if (!$form_state['skip']) {
  322. // Merge the broken apart array neatly back together.
  323. $allowed_content_types = array();
  324. foreach ($form_state['values']['allowed'] as $allowed) {
  325. $values = $form_state['values']['content_types'][$allowed]['options'];
  326. // If new content of the type is not added, storing a lisy of disabled
  327. // content is not needed.
  328. if (!$form_state['values']['panels_common_default'][$allowed]) {
  329. $values = array_filter($values);
  330. }
  331. $allowed_content_types = array_merge($allowed_content_types, $values);
  332. }
  333. // Values from checkboxes are the same string as they key, but we only need
  334. // to store the boolean value.
  335. foreach ($allowed_content_types as &$value) {
  336. $value = (bool) $value;
  337. }
  338. variable_set($module_name . '_allowed_types', $allowed_content_types);
  339. }
  340. drupal_set_message(t('Your changes have been saved.'));
  341. }
  342. /**
  343. * Based upon the settings, get the allowed types for this node.
  344. */
  345. function panels_common_get_allowed_types($module, $contexts = array(), $has_content = FALSE, $default_defaults = array(), $default_allowed_types = array()) {
  346. // Get a list of all types that are available.
  347. $default_types = variable_get($module . '_default', $default_defaults);
  348. $allowed_types = variable_get($module . '_allowed_types', $default_allowed_types);
  349. // By default, if they haven't gone and done the initial setup here,
  350. // let all 'other' types (which will be all types) be available.
  351. if (!isset($default_types['other'])) {
  352. $default_types['other'] = TRUE;
  353. }
  354. ctools_include('content');
  355. $content_types = ctools_content_get_available_types($contexts, $has_content, $allowed_types, $default_types);
  356. return $content_types;
  357. }
  358. /**
  359. * The FAPI code for generating an 'allowed layouts' selection form.
  360. *
  361. * NOTE: Because the Panels API does not guarantee a particular method of storing the data on allowed layouts,
  362. * it is not_possible for the Panels API to implement any checks that determine whether reductions in
  363. * the set of allowed layouts conflict with pre-existing layout selections. $displays in that category
  364. * will continue to function with their current layout as normal until the user/owner/admin attempts
  365. * to change layouts on that display, at which point they will have to select from the new set of
  366. * allowed layouts. If this is not the desired behavior for your client module, it's up to you to
  367. * write a validation routine that determines what should be done with conflicting layouts.
  368. *
  369. * Remember that changing layouts where panes have already been created can result in data loss;
  370. * consult panels_change_layout() to see how the Panels API handles that process. Running
  371. * drupal_execute('panels_change_layout', ...) is one possible starting point.
  372. *
  373. * @ingroup forms
  374. *
  375. * @param array $allowed_layouts
  376. * The set of allowed layouts that should be used as the default values
  377. * for this form. If none is provided, then by default no layouts will be restricted.
  378. */
  379. function panels_common_allowed_layouts_form(&$form, &$form_state, $module_name) {
  380. // Fetch our allowed layouts from variables.
  381. $allowed_layouts = panels_common_get_allowed_layout_object($module_name);
  382. $layouts = panels_get_layouts();
  383. foreach ($layouts as $id => $layout) {
  384. $options[$id] = panels_print_layout_icon($id, $layout, check_plain($layout['title']));
  385. }
  386. $form_state['allowed_layouts'] = &$allowed_layouts;
  387. ctools_add_js('panels-base', 'panels');
  388. ctools_add_js('layout', 'panels');
  389. $form['layout_selection'] = array(
  390. '#type' => 'fieldset',
  391. '#title' => t('Select allowed layouts'),
  392. '#group' => 'additional_settings',
  393. '#weight' => 10,
  394. );
  395. $form['layout_selection']['layouts'] = array(
  396. '#type' => 'checkboxes',
  397. '#options' => $options,
  398. '#description' => t('Check the boxes for all layouts you want to allow users choose from when picking a layout. You must allow at least one layout.'),
  399. '#default_value' => array_keys(array_filter($allowed_layouts->allowed_layout_settings)),
  400. '#prefix' => '<div class="clearfix panels-layouts-checkboxes">',
  401. '#suffix' => '</div>',
  402. '#checkall' => TRUE,
  403. );
  404. return $form;
  405. }
  406. function panels_common_allowed_layouts_form_validate($form, &$form_state) {
  407. $selected = array_filter($form_state['values']['layouts']);
  408. if (empty($selected)) {
  409. form_set_error('layouts', 'You must choose at least one layout to allow.');
  410. }
  411. }
  412. function panels_common_allowed_layouts_form_submit($form, &$form_state) {
  413. foreach ($form_state['values']['layouts'] as $layout => $setting) {
  414. $form_state['allowed_layouts']->allowed_layout_settings[$layout] = (bool) $setting;
  415. }
  416. $form_state['allowed_layouts']->save();
  417. }
  418. /**
  419. * Get the allowed layout object for the given module.
  420. */
  421. function panels_common_get_allowed_layout_object($module_name) {
  422. $allowed_layouts = unserialize(variable_get($module_name . "_allowed_layouts", serialize('')));
  423. // If no parameter was provided, or the variable_get failed.
  424. if (!$allowed_layouts) {
  425. // Still no dice. simply creates a dummy version where all layouts
  426. // are allowed.
  427. $allowed_layouts = new panels_allowed_layouts();
  428. $allowed_layouts->allow_new = TRUE;
  429. $allowed_layouts->module_name = $module_name;
  430. }
  431. // Sanitize allowed layout listing; this is redundant if the
  432. // $allowed_layouts param was null, but the data is cached anyway.
  433. $allowed_layouts->sync_with_available();
  434. return $allowed_layouts;
  435. }
  436. /**
  437. * Get the allowed layouts for the given module.
  438. */
  439. function panels_common_get_allowed_layouts($module_name) {
  440. ctools_include('plugins', 'panels');
  441. $available_layouts = panels_get_layouts();
  442. if (empty($module_name)) {
  443. return $available_layouts;
  444. }
  445. elseif (is_object($module_name)) {
  446. $allowed_layouts = $module_name;
  447. }
  448. else {
  449. $allowed_layouts = panels_common_get_allowed_layout_object($module_name);
  450. }
  451. $allowed = array_filter($allowed_layouts->allowed_layout_settings);
  452. $order = array();
  453. foreach ($available_layouts as $name => $plugin) {
  454. if (!empty($allowed[$name])) {
  455. $order[$name] = $plugin['category'] . ':' . $plugin['title'];
  456. }
  457. }
  458. // Sort.
  459. $layouts = array();
  460. asort($order);
  461. foreach ($order as $name => $junk) {
  462. $layouts[$name] = $available_layouts[$name];
  463. }
  464. return $layouts;
  465. }
  466. /**
  467. * Create a visible list of content in a display.
  468. * Note that the contexts must be pre-loaded.
  469. */
  470. function theme_panels_common_content_list($vars) {
  471. $display = $vars['display'];
  472. $layout = panels_get_layout($display->layout);
  473. $content = '<dl class="content-list">';
  474. foreach (panels_get_regions($layout, $display) as $panel_id => $title) {
  475. $content .= "<dt>$title</dt><dd>";
  476. if (!empty($display->panels[$panel_id])) {
  477. $content .= '<ol>';
  478. foreach ($display->panels[$panel_id] as $pid) {
  479. $content .= '<li>' . panels_get_pane_title($display->content[$pid], $display->context) . '</li>';
  480. }
  481. $content .= '</ol>';
  482. }
  483. else {
  484. $content .= t('Empty');
  485. }
  486. $content .= '</dd>';
  487. }
  488. $content .= '</dl>';
  489. return $content;
  490. }
  491. /**
  492. * Print a selector of layouts, each linked to the next step.
  493. *
  494. * Most operations use radio buttons for selecting layouts, but some will
  495. * give each layout as a link that goes to the next step. This function
  496. * makes it easy to simply provide a list of allowed layouts and the base
  497. * path.
  498. *
  499. * One limitation is that it will only append the layout name to the end, so
  500. * if the actual layout name is needed in the middle, that can't happen.
  501. *
  502. * @return
  503. * The rendered output.
  504. */
  505. function panels_common_print_layout_links($layouts, $base_path, $link_options = array(), $current_layout = NULL) {
  506. $output = '';
  507. $categories = array();
  508. ctools_include('cleanstring');
  509. $default_category = '';
  510. foreach ($layouts as $id => $layout) {
  511. $category = ctools_cleanstring($layout['category']);
  512. $categories[$category] = $layout['category'];
  513. if ($id == $current_layout) {
  514. $default_category = $category;
  515. }
  516. $options[$category][$id] = panels_print_layout_link($id, $layout, $base_path . '/' . $id, $link_options, $current_layout);
  517. }
  518. $form = array();
  519. $form['categories'] = array(
  520. '#title' => t('Category'),
  521. '#type' => 'select',
  522. '#options' => $categories,
  523. '#name' => 'categories',
  524. '#id' => 'edit-categories',
  525. '#value' => $default_category,
  526. '#parents' => array('categories'),
  527. '#access' => (count($categories) > 1) ? TRUE : FALSE,
  528. );
  529. $output .= drupal_render($form);
  530. $output .= '<div class="panels-choose-layout panels-layouts-checkboxes clearfix">';
  531. // We're doing these dependencies completely manualy, which is unusual, but
  532. // the process code only supports doing them in a form.
  533. // @todo modify dependent.inc to make this easier.
  534. $dependencies = array();
  535. foreach ($options as $category => $links) {
  536. $dependencies['panels-layout-category-' . $category] = array(
  537. 'values' => array('edit-categories' => array($category)),
  538. 'num' => 1,
  539. 'type' => 'hide',
  540. );
  541. $output .= '<div id="panels-layout-category-' . $category . '-wrapper">';
  542. $output .= '<div id="panels-layout-category-' . $category . '" class="form-checkboxes clearfix">';
  543. $output .= (count($categories) > 1) ? '<div class="panels-layouts-category">' . $categories[$category] . '</div>' : '';
  544. foreach ($links as $key => $link) {
  545. $output .= $link;
  546. }
  547. $output .= '</div></div>';
  548. }
  549. $output .= '</div>';
  550. ctools_add_js('dependent');
  551. $js['CTools']['dependent'] = $dependencies;
  552. drupal_add_js($js, 'setting');
  553. return $output;
  554. }