common.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. */
  41. class panels_allowed_layouts {
  42. /**
  43. * Specifies whether newly-added layouts (as in, new .inc files) should be automatically
  44. * allowed (TRUE) or disallowed (FALSE) for $this. Defaults to TRUE, which is more
  45. * permissive but less of an administrative hassle if/when you add new layouts. Note
  46. * that this parameter will be derived from $allowed_layouts if a value is passed in.
  47. */
  48. var $allow_new = TRUE;
  49. /**
  50. * Optional member. If provided, the Panels API will generate a drupal variable using
  51. * variable_set($module_name . 'allowed_layouts', serialize($this)), thereby handling the
  52. * storage of this object entirely within the Panels API. This object will be
  53. * called and rebuilt by panels_edit_layout() if the same $module_name string is passed in
  54. * for the $allowed_types parameter. \n
  55. * This is primarily intended for convenience - client modules doing heavy-duty implementations
  56. * of the Panels API will probably want to create their own storage method.
  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. */
  84. function __construct($start_allowed = TRUE) {
  85. // TODO would be nice if there was a way to just fetch the names easily
  86. foreach ($this->list_layouts() as $layout_name) {
  87. $this->allowed_layout_settings[$layout_name] = $start_allowed ? 1 : 0;
  88. }
  89. }
  90. /**
  91. * Manage panels_common_set_allowed_layouts(), the FAPI code for selecting allowed layouts.
  92. *
  93. * MAKE SURE to set panels_allowed_layouts::allow_new before calling this method. If you want the panels API
  94. * to handle saving these allowed layout settings, panels_allowed_layouts::module_name must also be set.
  95. *
  96. * Below is a sample implementation; refer to the rest of the class documentation to understand all the
  97. * specific pieces. Values that are intended to be replaced are wrapped with <>.
  98. *
  99. * \n @code
  100. * function docdemo_allowed_layouts() {
  101. * ctools_include('common', 'panels');
  102. * if (!is_a($allowed_layouts = unserialize(variable_get('panels_common_allowed_layouts', serialize(''))), 'panels_allowed_layouts')) {
  103. * $allowed_layouts = new panels_allowed_layouts();
  104. * $allowed_layouts->allow_new = TRUE;
  105. * $allowed_layouts->module_name = '<client_module_name>';
  106. * }
  107. * $result = $allowed_layouts->set_allowed('<Desired client module form title>');
  108. * if (in_array($allowed_layouts->form_state, array('failed-validate', 'render'))) {
  109. * return $result;
  110. * }
  111. * elseif ($allowed_layouts->form_state == 'submit') {
  112. * drupal_goto('</path/to/desired/redirect>');
  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. */
  185. function save() {
  186. if (!is_null($this->module_name)) {
  187. variable_set($this->module_name . "_allowed_layouts", serialize($this));
  188. }
  189. }
  190. /**
  191. * Snag a list of the current layouts for internal use.
  192. *
  193. * Data is not saved in a class member in order to ensure that it's
  194. * fresh.
  195. *
  196. * @return array $layouts
  197. * An indexed array of the system names for all currently available layouts.
  198. */
  199. function list_layouts() {
  200. static $layouts = array();
  201. if (empty($layouts)) {
  202. ctools_include('plugins', 'panels');
  203. $layouts = array_keys(panels_get_layouts());
  204. }
  205. return $layouts;
  206. }
  207. }
  208. /**
  209. * A common settings page for Panels modules, because this code is relevant to
  210. * any modules that don't already have special requirements.
  211. */
  212. function panels_common_settings($form, &$form_state, $module_name = 'panels_common') {
  213. ctools_include('plugins', 'panels');
  214. ctools_include('content');
  215. $content_types = ctools_get_content_types();
  216. $skip = FALSE;
  217. $default_types = variable_get($module_name . '_default', NULL);
  218. if (!isset($default_types)) {
  219. $default_types = array('other' => TRUE);
  220. $skip = TRUE;
  221. }
  222. foreach ($content_types as $id => $info) {
  223. if (empty($info['single'])) {
  224. $default_options[$id] = t('New @s', array('@s' => $info['title']));
  225. if ($skip) {
  226. $default_types[$id] = TRUE;
  227. }
  228. }
  229. }
  230. $default_options['other'] = t('New content of other types');
  231. $form['additional_settings'] = array(
  232. '#type' => 'vertical_tabs',
  233. );
  234. $form['common'] = array(
  235. '#type' => 'fieldset',
  236. '#title' => t('New content behavior'),
  237. '#group' => 'additional_settings',
  238. '#weight' => -10,
  239. );
  240. $form['common']['panels_common_default'] = array(
  241. '#type' => 'checkboxes',
  242. '#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.'),
  243. '#options' => $default_options,
  244. '#default_value' => array_keys(array_filter($default_types)),
  245. );
  246. $form_state['skip'] = $skip;
  247. if ($skip) {
  248. $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>'));
  249. }
  250. else {
  251. // Rebuild the entire list, setting appropriately from defaults. Give
  252. // each type its own checkboxes set unless it's 'single' in which
  253. // case it can go into our fake other set.
  254. $available_content_types = ctools_content_get_all_types();
  255. $allowed_content_types = variable_get($module_name . '_allowed_types', array());
  256. foreach ($available_content_types as $id => $types) {
  257. foreach ($types as $type => $info) {
  258. $key = $id . '-' . $type;
  259. $checkboxes = empty($content_types[$id]['single']) ? $id : 'other';
  260. $options[$checkboxes][$key] = $info['title'];
  261. if (!isset($allowed_content_types[$key])) {
  262. $allowed[$checkboxes][$key] = isset($default_types[$id]) ? $default_types[$id] : $default_types['other'];
  263. }
  264. else {
  265. $allowed[$checkboxes][$key] = $allowed_content_types[$key];
  266. }
  267. }
  268. }
  269. $form['content_types'] = array(
  270. '#tree' => TRUE,
  271. );
  272. // cheat a bit
  273. $content_types['other'] = array('title' => t('Other'), 'weight' => 10);
  274. foreach ($content_types as $id => $info) {
  275. if (isset($allowed[$id])) {
  276. $form['content_types'][$id] = array(
  277. '#type' => 'fieldset',
  278. '#group' => 'additional_settings',
  279. '#title' => t('Allowed @s content', array('@s' => $info['title'])),
  280. );
  281. $form['content_types'][$id]['options'] = array(
  282. '#prefix' => '<div class="panels-page-type-container">',
  283. '#suffix' => '</div>',
  284. '#type' => 'checkboxes',
  285. '#options' => $options[$id],
  286. '#default_value' => array_keys(array_filter($allowed[$id])),
  287. '#checkall' => TRUE,
  288. );
  289. }
  290. }
  291. }
  292. // Layout selection.
  293. panels_common_allowed_layouts_form($form, $form_state, $module_name);
  294. $form['allowed'] = array(
  295. '#type' => 'value',
  296. '#value' => isset($allowed) ? array_keys($allowed) : array(),
  297. );
  298. $form['module_name'] = array(
  299. '#type' => 'value',
  300. '#value' => $module_name,
  301. );
  302. $form['submit'] = array(
  303. '#type' => 'submit',
  304. '#value' => t('Save'),
  305. );
  306. ctools_add_css('panels_page', 'panels');
  307. return $form;
  308. }
  309. /**
  310. * Submit hook for panels_common_settings
  311. */
  312. function panels_common_settings_validate($form, &$form_state) {
  313. panels_common_allowed_layouts_form_validate($form, $form_state);
  314. }
  315. /**
  316. * Submit hook for panels_common_settings
  317. */
  318. function panels_common_settings_submit($form, &$form_state) {
  319. panels_common_allowed_layouts_form_submit($form, $form_state);
  320. $module_name = $form_state['values']['module_name'];
  321. variable_set($module_name . '_default', $form_state['values']['panels_common_default']);
  322. if (!$form_state['skip']) {
  323. // Merge the broken apart array neatly back together.
  324. $allowed_content_types = array();
  325. foreach ($form_state['values']['allowed'] as $allowed) {
  326. $values = $form_state['values']['content_types'][$allowed]['options'];
  327. // If new content of the type is not added, storing a lisy of disabled
  328. // content is not needed.
  329. if (!$form_state['values']['panels_common_default'][$allowed]) {
  330. $values = array_filter($values);
  331. }
  332. $allowed_content_types = array_merge($allowed_content_types, $values);
  333. }
  334. // Values from checkboxes are the same string as they key, but we only need
  335. // to store the boolean value.
  336. foreach ($allowed_content_types as &$value) {
  337. $value = (bool) $value;
  338. }
  339. variable_set($module_name . '_allowed_types', $allowed_content_types);
  340. }
  341. drupal_set_message(t('Your changes have been saved.'));
  342. }
  343. /**
  344. * Based upon the settings, get the allowed types for this node.
  345. */
  346. function panels_common_get_allowed_types($module, $contexts = array(), $has_content = FALSE, $default_defaults = array(), $default_allowed_types = array()) {
  347. // Get a list of all types that are available
  348. $default_types = variable_get($module . '_default', $default_defaults);
  349. $allowed_types = variable_get($module . '_allowed_types', $default_allowed_types);
  350. // By default, if they haven't gone and done the initial setup here,
  351. // let all 'other' types (which will be all types) be available.
  352. if (!isset($default_types['other'])) {
  353. $default_types['other'] = TRUE;
  354. }
  355. ctools_include('content');
  356. $content_types = ctools_content_get_available_types($contexts, $has_content, $allowed_types, $default_types);
  357. return $content_types;
  358. }
  359. /**
  360. * The FAPI code for generating an 'allowed layouts' selection form.
  361. *
  362. * NOTE: Because the Panels API does not guarantee a particular method of storing the data on allowed layouts,
  363. * it is not_possible for the Panels API to implement any checks that determine whether reductions in
  364. * the set of allowed layouts conflict with pre-existing layout selections. $displays in that category
  365. * will continue to function with their current layout as normal until the user/owner/admin attempts
  366. * to change layouts on that display, at which point they will have to select from the new set of
  367. * allowed layouts. If this is not the desired behavior for your client module, it's up to you to
  368. * write a validation routine that determines what should be done with conflicting layouts.
  369. *
  370. * Remember that changing layouts where panes have already been created can result in data loss;
  371. * consult panels_change_layout() to see how the Panels API handles that process. Running
  372. * drupal_execute('panels_change_layout', ...) is one possible starting point.
  373. *
  374. * @ingroup forms
  375. *
  376. * @param array $allowed_layouts
  377. * The set of allowed layouts that should be used as the default values
  378. * for this form. If none is provided, then by default no layouts will be restricted.
  379. */
  380. function panels_common_allowed_layouts_form(&$form, &$form_state, $module_name) {
  381. // Fetch our allowed layouts from variables.
  382. $allowed_layouts = panels_common_get_allowed_layout_object($module_name);
  383. $layouts = panels_get_layouts();
  384. foreach ($layouts as $id => $layout) {
  385. $options[$id] = panels_print_layout_icon($id, $layout, check_plain($layout['title']));
  386. }
  387. $form_state['allowed_layouts'] = &$allowed_layouts;
  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. else if (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. }