Projet

Général

Profil

Paste
Télécharger (23,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / includes / common.inc @ fc3d89c3

1
<?php
2

    
3

    
4
/**
5
 * @file
6
 * Functions used by more than one panels client module.
7
 */
8

    
9
/**
10
 * Class definition for the allowed layouts governing structure.
11
 *
12
 * @ingroup mainapi
13
 *
14
 * This class is designed to handle panels allowed layouts data from start to finish, and sees
15
 * action at two times:\n
16
 *    - When a client module wants to generate a form allowing an admin to create or edit a set
17
 *      of allowed layouts. In this case, either a new panels_allowed_layouts object is created
18
 *      or one is retrieved from storage and panels_allowed_layouts::set_allowed() is called to
19
 *      generate the allowed layouts form. \n
20
 *    - When a client module is calling panels_edit_layout(), a saved instantiation of this object
21
 *      can be called up and passed in to the fourth parameter, and only the allowed layouts saved
22
 *      in that object will be displayed on the form. \n
23
 * Because the panels API does not impose a data structure on the allowed_layouts data, client
24
 * modules can create as many of these objects as they want, and organize them around any concept:
25
 * node types, date published, author roles...anything.
26
 *
27
 * To call the settings form, instantiate this class - or, if your client module's needs are
28
 * heavy-duty, extend this class and instantiate your subclass - assign values to any relevant
29
 * desired members, and call panels_allowed_layouts::set_allowed(). See the documentation on
30
 * that method for a sample implementation.
31
 *
32
 * Note that when unserializing saved tokens of this class, you must
33
 * run panels_load_include('common') before unserializing in order to ensure
34
 * that the object is properly loaded.
35
 *
36
 * Client modules extending this class should implement a save() method and use it for
37
 * their custom data storage routine. You'll need to rewrite other class methods if
38
 * you choose to go another route.
39
 *
40
 * @see panels_edit_layout()
41
 * @see _panels_edit_layout()
42
 *
43
 */
44
class panels_allowed_layouts {
45

    
46
  /**
47
   *  Specifies whether newly-added layouts (as in, new .inc files) should be automatically
48
   *  allowed (TRUE) or disallowed (FALSE) for $this. Defaults to TRUE, which is more
49
   *  permissive but less of an administrative hassle if/when you add new layouts. Note
50
   *  that this parameter will be derived from $allowed_layouts if a value is passed in.
51
   */
52
  var $allow_new = TRUE;
53

    
54
  /**
55
   *  Optional member. If provided, the Panels API will generate a drupal variable using
56
   *  variable_set($module_name . 'allowed_layouts', serialize($this)), thereby handling the
57
   *  storage of this object entirely within the Panels API. This object will be
58
   *  called and rebuilt by panels_edit_layout() if the same $module_name string is passed in
59
   *  for the $allowed_types parameter. \n
60
   *  This is primarily intended for convenience - client modules doing heavy-duty implementations
61
   *  of the Panels API will probably want to create their own storage method.
62
   * @see panels_edit_layout()
63
   */
64
  var $module_name = NULL;
65

    
66
  /**
67
   *  An associative array of all available layouts, keyed by layout name (as defined
68
   *  in the corresponding layout plugin definition), with value = 1 if the layout is
69
   *  allowed, and value = 0 if the layout is not allowed.
70
   *  Calling array_filter(panels_allowed_layouts::$allowed_layout_settings) will return an associative array
71
   *  containing only the allowed layouts, and wrapping that in array_keys() will
72
   *  return an indexed version of that array.
73
   */
74
  var $allowed_layout_settings = array();
75

    
76
  /**
77
   * Hack-imitation of D6's $form_state. Used by the panels_common_set_allowed_types()
78
   * form to indicate whether the returned value is in its 'render', 'failed-validate',
79
   * or 'submit' stage.
80
   */
81
  var $form_state;
82

    
83
  /**
84
   * Constructor function; loads the $allowed_layout_settings array with initial values according
85
   * to $start_allowed
86
   *
87
   * @param bool $start_allowed
88
   *  $start_allowed determines whether all available layouts will be marked
89
   *  as allowed or not allowed on the initial call to panels_allowed_layouts::set_allowed()
90
   *
91
   */
92
  function __construct($start_allowed = TRUE) {
93
    // TODO would be nice if there was a way to just fetch the names easily
94
    foreach ($this->list_layouts() as $layout_name) {
95
      $this->allowed_layout_settings[$layout_name] = $start_allowed ? 1 : 0;
96
    }
97
  }
98

    
99
  /**
100
   * Manage panels_common_set_allowed_layouts(), the FAPI code for selecting allowed layouts.
101
   *
102
   * MAKE SURE to set panels_allowed_layouts::allow_new before calling this method. If you want the panels API
103
   * to handle saving these allowed layout settings, panels_allowed_layouts::module_name must also be set.
104
   *
105
   * Below is a sample implementation; refer to the rest of the class documentation to understand all the
106
   * specific pieces. Values that are intended to be replaced are wrapped with <>.
107
   *
108
   * \n @code
109
   *  function docdemo_allowed_layouts() {
110
   *    ctools_include('common', 'panels');
111
   *    if (!is_a($allowed_layouts = unserialize(variable_get('panels_common_allowed_layouts', serialize(''))), 'panels_allowed_layouts')) {
112
   *     $allowed_layouts = new panels_allowed_layouts();
113
   *      $allowed_layouts->allow_new = TRUE;
114
   *      $allowed_layouts->module_name = '<client_module_name>';
115
   *    }
116
   *    $result = $allowed_layouts->set_allowed('<Desired client module form title>');
117
   *    if (in_array($allowed_layouts->form_state, array('failed-validate', 'render'))) {
118
   *     return $result;
119
   *    }
120
   *    elseif ($allowed_layouts->form_state == 'submit') {
121
   *      drupal_goto('</path/to/desired/redirect>');
122
   *    }
123
   *  }
124
   * @endcode \n
125
   *
126
   * If $allowed_layouts->form_state == 'failed-validate' || 'render', then you'll need to return
127
   * $result as it contains the structured form HTML generated by drupal_render_form() and is ready
128
   * to be passed through index.php's call to theme('page', ...).
129
   *
130
   * However, if $allowed_layouts->form_state == 'submit', then the form has been submitted and we should
131
   * react. It's really up to your client module how you handle the rest; panels_allowed_layouts::save() (or
132
   * panels_allowed_layouts::api_save(), if that's the route you're going) will have already been called,
133
   * so if those methods handle your save routine, then all there is left to do is handle redirects, if you
134
   * want. The current implementation of the allowed layouts form currently never redirects, so it's up to
135
   * you to control where the user ends up next.
136
   *
137
   * @param string $title
138
   *  Used to set the title of the allowed layouts form. If no value is given, defaults to
139
   *  'Panels: Allowed Layouts'.
140
   *
141
   * @return mixed $result
142
   *  - On the first passthrough when the form is being rendered, $result is the form's structured
143
   *    HTML, ready to be pushed to the screen with a call to theme('page', ...).
144
   *  - A successful second passthrough indicates a successful submit, and
145
   *    $result === panels_allowed_layouts::allowed_layout_settings. Returning it is simply for convenience.
146
   */
147
  function set_allowed($title = 'Panels: Allowed Layouts') {
148
    $this->sync_with_available();
149
    $form_id = 'panels_common_set_allowed_layouts';
150
    // TODO switch to drupal_build_form(); need to pass by ref
151
    $form = drupal_retrieve_form($form_id, $this, $title);
152

    
153
    if ($result = drupal_process_form($form_id, $form)) {
154
      // successful submit
155
      $this->form_state = 'submit';
156
      return $result;
157
    }
158
    $this->form_state = isset($_POST['op']) ? 'failed-validate' : 'render';
159
    $result = drupal_render_form($form_id, $form);
160
    return $result;
161
  }
162

    
163
  /**
164
   * Checks for newly-added layouts and deleted layouts. If any are found, updates panels_allowed_layouts::allowed_layout_settings;
165
   * new additions are made according to panels_allowed_layouts::allow_new, while deletions are unset().
166
   *
167
   * Note that any changes made by this function are not saved in any permanent location.
168
   */
169
  function sync_with_available() {
170
    $layouts = $this->list_layouts();
171
    foreach (array_diff($layouts, array_keys($this->allowed_layout_settings)) as $new_layout) {
172
      $this->allowed_layout_settings[$new_layout] = $this->allow_new ? 1 : 0;
173
    }
174
    foreach (array_diff(array_keys($this->allowed_layout_settings), $layouts) as $deleted_layout) {
175
      unset($this->allowed_layout_settings[$deleted_layout]);
176
    }
177
  }
178

    
179
  /**
180
   * Use panels_allowed_layouts::module_name to generate a variable for variable_set(), in which
181
   * a serialized version of $this will be stored.
182
   *
183
   * Does nothing if panels_allowed_layouts::module_name is not set.
184
   *
185
   * IMPORTANT NOTE: if you use variable_get() in a custom client module save() method, you MUST
186
   * wrap $this in serialize(), then unserialize() what you get from variable_get(). Failure to
187
   * do so will result in an incomplete object. The following code will work:
188
   * @code
189
   *  $allowed_layouts = unserialize(variable_get('your_variable_name', serialize(''));
190
   * @endcode
191
   *
192
   * If you don't serialize the second parameter of variable_get() and the variable name you provide
193
   * can't be found, an E_STRICT warning will be generated for trying to unserialize an entity
194
   * that has not been serialized.
195
   *
196
   */
197
  function save() {
198
    if (!is_null($this->module_name)) {
199
      variable_set($this->module_name . '_allowed_layouts', serialize($this));
200
    }
201
  }
202

    
203
  /**
204
   * Snag a list of the current layouts for internal use.
205
   *
206
   * Data is not saved in a class member in order to ensure that it's
207
   * fresh.
208
   *
209
   * @return array $layouts
210
   *  An indexed array of the system names for all currently available layouts.
211
   */
212
  function list_layouts() {
213
    static $layouts = array();
214
    if (empty($layouts)) {
215
      ctools_include('plugins', 'panels');
216
      $layouts = array_keys(panels_get_layouts());
217
    }
218
    return $layouts;
219
  }
220
}
221

    
222
/**
223
 * A common settings page for Panels modules, because this code is relevant to
224
 * any modules that don't already have special requirements.
225
 */
226
function panels_common_settings($form, &$form_state, $module_name = 'panels_common') {
227
  ctools_include('plugins', 'panels');
228
  ctools_include('content');
229
  $content_types = ctools_get_content_types();
230
  $skip = FALSE;
231

    
232
  $default_types = variable_get($module_name . '_default', NULL);
233
  if (!isset($default_types)) {
234
    $default_types = array('other' => TRUE);
235
    $skip = TRUE;
236
  }
237

    
238
  foreach ($content_types as $id => $info) {
239
    if (empty($info['single'])) {
240
      $default_options[$id] = t('New @s', array('@s' => $info['title']));
241
      if ($skip) {
242
        $default_types[$id] = TRUE;
243
      }
244
    }
245
  }
246

    
247
  $default_options['other'] = t('New content of other types');
248

    
249
  $form['additional_settings'] = array(
250
    '#type' => 'vertical_tabs',
251
  );
252

    
253
  $form['common'] = array(
254
    '#type' => 'fieldset',
255
    '#title' => t('New content behavior'),
256
    '#group' => 'additional_settings',
257
    '#weight' => -10,
258
  );
259
  $form['common']['panels_common_default'] = array(
260
    '#type' => 'checkboxes',
261
    '#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.'),
262
    '#options' => $default_options,
263
    '#default_value' => array_keys(array_filter($default_types)),
264
  );
265

    
266
  $form_state['skip'] = $skip;
267
  if ($skip) {
268
    $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>'));
269
  }
270
  else {
271
    // Rebuild the entire list, setting appropriately from defaults. Give
272
    // each type its own checkboxes set unless it's 'single' in which
273
    // case it can go into our fake other set.
274
    $available_content_types = ctools_content_get_all_types();
275
    $allowed_content_types = db_select('panels_allowed_types', 'pat')
276
      ->fields('pat', array('type', 'allowed'))
277
      ->condition('module', $module_name)
278
      ->execute()
279
      ->fetchAllKeyed();
280

    
281
    foreach ($available_content_types as $id => $types) {
282
      foreach ($types as $type => $info) {
283
        $key = $id . '-' . $type;
284
        $checkboxes = empty($content_types[$id]['single']) ? $id : 'other';
285
        $options[$checkboxes][$key] = $info['title'];
286
        if (!isset($allowed_content_types[$key])) {
287
          $allowed[$checkboxes][$key] = isset($default_types[$id]) ? $default_types[$id] : $default_types['other'];
288
        }
289
        else {
290
          $allowed[$checkboxes][$key] = $allowed_content_types[$key];
291
        }
292
      }
293
    }
294

    
295
    $form['content_types'] = array(
296
      '#tree' => TRUE,
297
    );
298

    
299
    // cheat a bit
300
    $content_types['other'] = array('title' => t('Other'), 'weight' => 10);
301
    foreach ($content_types as $id => $info) {
302
      if (isset($allowed[$id])) {
303

    
304
        $form['content_types'][$id] = array(
305
          '#type' => 'fieldset',
306
          '#group' => 'additional_settings',
307
          '#title' => t('Allowed @s content', array('@s' => $info['title'])),
308
        );
309

    
310
        $form['content_types'][$id]['options'] = array(
311
          '#prefix' => '<div class="panels-page-type-container">',
312
          '#suffix' => '</div>',
313
          '#type' => 'checkboxes',
314
          '#options' => $options[$id],
315
          '#default_value' => array_keys(array_filter($allowed[$id])),
316
          '#checkall' => TRUE,
317
        );
318
      }
319
    }
320
  }
321

    
322
  // Layout selection.
323
  panels_common_allowed_layouts_form($form, $form_state, $module_name);
324

    
325
  $form['allowed'] = array(
326
    '#type' => 'value',
327
    '#value' => isset($allowed) ? array_keys($allowed) : array(),
328
  );
329

    
330
  $form['module_name'] = array(
331
    '#type' => 'value',
332
    '#value' => $module_name,
333
  );
334

    
335
  $form['submit'] = array(
336
    '#type' => 'submit',
337
    '#value' => t('Save'),
338
  );
339

    
340
  ctools_add_css('panels_page', 'panels');
341
  return $form;
342
}
343

    
344
/**
345
 * Submit hook for panels_common_settings
346
 */
347
function panels_common_settings_validate($form, &$form_state) {
348
  panels_common_allowed_layouts_form_validate($form, $form_state);
349
}
350

    
351
/**
352
 * Submit hook for panels_common_settings
353
 */
354
function panels_common_settings_submit($form, &$form_state) {
355
  panels_common_allowed_layouts_form_submit($form, $form_state);
356
  $module_name = $form_state['values']['module_name'];
357
  variable_set($module_name . '_default', $form_state['values']['panels_common_default']);
358
  if (!$form_state['skip']) {
359
    // Merge the broken apart array neatly back together.
360
    $allowed_content_types = array();
361
    $content_types = $form_state['values']['allowed'];
362
    foreach ($content_types as $content_type) {
363
      $allowed_content_types = array_merge($allowed_content_types, $form_state['values']['content_types'][$content_type]['options']);
364
      foreach ($allowed_content_types as $type => $allowed) {
365
        $allowed = empty($allowed) ? 0 : 1;
366
        db_merge('panels_allowed_types')
367
          ->key(array('module' => $module_name, 'type' => $type))
368
          ->fields(array(
369
            'module' => $module_name,
370
            'type' => $type,
371
            'allowed' => $allowed,
372
          ))
373
          ->execute();
374
      }
375
    }
376
  }
377
  drupal_set_message(t('Your changes have been saved.'));
378
}
379

    
380
/**
381
 * Based upon the settings, get the allowed types for this node.
382
 */
383
function panels_common_get_allowed_types($module, $contexts = array(), $has_content = FALSE, $default_defaults = array(), $default_allowed_types = array()) {
384
  // Get a list of all types that are available
385
  $default_types = variable_get($module . '_default', $default_defaults);
386
  $allowed_types = db_select('panels_allowed_types', 'pat')
387
    ->fields('pat', array('type', 'allowed'))
388
    ->condition('module', $module)
389
    ->execute()
390
    ->fetchAllKeyed();
391
  $allowed_types = !empty($allowed_types) ? $allowed_types : $default_allowed_types;
392

    
393
  // By default, if they haven't gone and done the initial setup here,
394
  // let all 'other' types (which will be all types) be available.
395
  if (!isset($default_types['other'])) {
396
    $default_types['other'] = TRUE;
397
  }
398

    
399
  ctools_include('content');
400
  $content_types = ctools_content_get_available_types($contexts, $has_content, $allowed_types, $default_types);
401

    
402
  return $content_types;
403
}
404

    
405
/**
406
 * The FAPI code for generating an 'allowed layouts' selection form.
407
 *
408
 * NOTE: Because the Panels API does not guarantee a particular method of storing the data on allowed layouts,
409
 * it is not_possible for the Panels API to implement any checks that determine whether reductions in
410
 * the set of allowed layouts conflict with pre-existing layout selections. $displays in that category
411
 * will continue to function with their current layout as normal until the user/owner/admin attempts
412
 * to change layouts on that display, at which point they will have to select from the new set of
413
 * allowed layouts. If this is not the desired behavior for your client module, it's up to you to
414
 * write a validation routine that determines what should be done with conflicting layouts.
415
 *
416
 * Remember that changing layouts where panes have already been created can result in data loss;
417
 * consult panels_change_layout() to see how the Panels API handles that process. Running
418
 * drupal_execute('panels_change_layout', ...) is one possible starting point.
419
 *
420
 * @ingroup forms
421
 *
422
 * @param array $allowed_layouts
423
 *  The set of allowed layouts that should be used as the default values
424
 *  for this form. If none is provided, then by default no layouts will be restricted.
425
 */
426
function panels_common_allowed_layouts_form(&$form, &$form_state, $module_name) {
427
  // Fetch our allowed layouts from variables.
428
  $allowed_layouts = panels_common_get_allowed_layout_object($module_name);
429

    
430
  $layouts = panels_get_layouts();
431
  foreach ($layouts as $id => $layout) {
432
    $options[$id] = panels_print_layout_icon($id, $layout, check_plain($layout['title']));
433
  }
434

    
435
  $form_state['allowed_layouts'] = &$allowed_layouts;
436

    
437
  ctools_add_js('layout', 'panels');
438

    
439
  $form['layout_selection'] = array(
440
    '#type' => 'fieldset',
441
    '#title' => t('Select allowed layouts'),
442
    '#group' => 'additional_settings',
443
    '#weight' => 10,
444
  );
445
  $form['layout_selection']['layouts'] = array(
446
    '#type' => 'checkboxes',
447
    '#options' => $options,
448
    '#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.'),
449
    '#default_value' => array_keys(array_filter($allowed_layouts->allowed_layout_settings)),
450
    '#prefix' => '<div class="clearfix panels-layouts-checkboxes">',
451
    '#suffix' => '</div>',
452
    '#checkall' => TRUE,
453
  );
454

    
455
  return $form;
456
}
457

    
458
function panels_common_allowed_layouts_form_validate($form, &$form_state) {
459
  $selected = array_filter($form_state['values']['layouts']);
460
  if (empty($selected)) {
461
    form_set_error('layouts', 'You must choose at least one layout to allow.');
462
  }
463
}
464

    
465
function panels_common_allowed_layouts_form_submit($form, &$form_state) {
466
  foreach ($form_state['values']['layouts'] as $layout => $setting) {
467
    $form_state['allowed_layouts']->allowed_layout_settings[$layout] = (bool) $setting;
468
  }
469
  $form_state['allowed_layouts']->save();
470
}
471

    
472
/**
473
 * Get the allowed layout object for the given module.
474
 */
475
function panels_common_get_allowed_layout_object($module_name) {
476
  $allowed_layouts = unserialize(variable_get($module_name . '_allowed_layouts', serialize('')));
477

    
478
  // if no parameter was provided, or the variable_get failed
479
  if (!$allowed_layouts) {
480
    // still no dice. simply creates a dummy version where all layouts
481
    // are allowed.
482
    $allowed_layouts = new panels_allowed_layouts();
483
    $allowed_layouts->allow_new = TRUE;
484
    $allowed_layouts->module_name = $module_name;
485
  }
486

    
487
  // sanitize allowed layout listing; this is redundant if the
488
  // $allowed_layouts param was null, but the data is cached anyway
489
  $allowed_layouts->sync_with_available();
490

    
491
  return $allowed_layouts;
492
}
493

    
494
/**
495
 * Get the allowed layouts for the given module.
496
 */
497
function panels_common_get_allowed_layouts($module_name) {
498
  ctools_include('plugins', 'panels');
499
  $available_layouts = panels_get_layouts();
500
  if (empty($module_name)) {
501
    return $available_layouts;
502
  }
503
  else if (is_object($module_name)) {
504
    $allowed_layouts = $module_name;
505
  }
506
  else {
507
    $allowed_layouts = panels_common_get_allowed_layout_object($module_name);
508
  }
509

    
510
  $allowed = array_filter($allowed_layouts->allowed_layout_settings);
511
  $order = array();
512
  foreach ($available_layouts as $name => $plugin) {
513
    if (!empty($allowed[$name])) {
514
      $order[$name] = $plugin['category'] . ':' . $plugin['title'];
515
    }
516
  }
517

    
518
  // Sort
519
  $layouts = array();
520

    
521
  asort($order);
522
  foreach ($order as $name => $junk) {
523
    $layouts[$name] = $available_layouts[$name];
524
  }
525

    
526
  return $layouts;
527
}
528

    
529
/**
530
 * Create a visible list of content in a display.
531
 * Note that the contexts must be pre-loaded.
532
 */
533
function theme_panels_common_content_list($vars) {
534
  $display = $vars['display'];
535

    
536
  $layout = panels_get_layout($display->layout);
537
  $content = '<dl class="content-list">';
538
  foreach (panels_get_regions($layout, $display) as $panel_id => $title) {
539
    $content .= "<dt>$title</dt><dd>";
540
    if (!empty($display->panels[$panel_id])) {
541
      $content .= '<ol>';
542
      foreach ($display->panels[$panel_id] as $pid) {
543
        $content .= '<li>' . panels_get_pane_title($display->content[$pid], $display->context) . '</li>';
544
      }
545
      $content .= '</ol>';
546
    }
547
    else {
548
      $content .= t('Empty');
549
    }
550
    $content .= '</dd>';
551
  }
552
  $content .= '</dl>';
553
  return $content;
554
}
555

    
556
/**
557
 * Print a selector of layouts, each linked to the next step.
558
 *
559
 * Most operations use radio buttons for selecting layouts, but some will
560
 * give each layout as a link that goes to the next step. This function
561
 * makes it easy to simply provide a list of allowed layouts and the base
562
 * path.
563
 *
564
 * One limitation is that it will only append the layout name to the end, so
565
 * if the actual layout name is needed in the middle, that can't happen.
566
 *
567
 * @return
568
 *   The rendered output.
569
 */
570
function panels_common_print_layout_links($layouts, $base_path, $link_options = array(), $current_layout = NULL) {
571
  $output = '';
572

    
573
  $categories = array();
574
  ctools_include('cleanstring');
575
  $default_category = '';
576
  foreach ($layouts as $id => $layout) {
577
    $category = ctools_cleanstring($layout['category']);
578

    
579
    $categories[$category] = $layout['category'];
580
    if ($id == $current_layout) {
581
      $default_category = $category;
582
    }
583

    
584
    $options[$category][$id] = panels_print_layout_link($id, $layout, $base_path . '/' . $id, $link_options, $current_layout);
585
  }
586

    
587
  $form = array();
588
  $form['categories'] = array(
589
    '#title' => t('Category'),
590
    '#type' => 'select',
591
    '#options' => $categories,
592
    '#name' => 'categories',
593
    '#id' => 'edit-categories',
594
    '#value' => $default_category,
595
    '#parents' => array('categories'),
596
    '#access' => (count($categories) > 1) ? TRUE : FALSE,
597
  );
598

    
599
  $output .= drupal_render($form);
600

    
601
  $output .= '<div class="panels-choose-layout panels-layouts-checkboxes clearfix">';
602

    
603
  // We're doing these dependencies completely manualy, which is unusual, but
604
  // the process code only supports doing them in a form.
605
  // @todo modify dependent.inc to make this easier.
606

    
607
  $dependencies = array();
608
  foreach ($options as $category => $links) {
609
    $dependencies['panels-layout-category-' . $category] = array(
610
      'values' => array('edit-categories' => array($category)),
611
      'num' => 1,
612
      'type' => 'hide',
613
    );
614

    
615
    $output .= '<div id="panels-layout-category-' . $category . '-wrapper">';
616
    $output .= '<div id="panels-layout-category-' . $category . '" class="form-checkboxes clearfix">';
617
    $output .= (count($categories) > 1) ? '<div class="panels-layouts-category">' . $categories[$category] . '</div>' : '';
618

    
619
    foreach ($links as $key => $link) {
620
      $output .= $link;
621
    }
622
    $output .= '</div></div>';
623
  }
624

    
625
  $output .= '</div>';
626

    
627
  ctools_add_js('dependent');
628
  $js['CTools']['dependent'] = $dependencies;
629
  drupal_add_js($js, 'setting');
630

    
631
  return $output;
632
}