You are here

function panels_common_print_layout_links in Panels 7.3

Same name and namespace in other branches
  1. 6.3 includes/common.inc \panels_common_print_layout_links()

Print a selector of layouts, each linked to the next step.

Most operations use radio buttons for selecting layouts, but some will give each layout as a link that goes to the next step. This function makes it easy to simply provide a list of allowed layouts and the base path.

One limitation is that it will only append the layout name to the end, so if the actual layout name is needed in the middle, that can't happen.

Return value

The rendered output.

2 calls to panels_common_print_layout_links()
panels_node_add in panels_node/panels_node.module
Override of node add page to force layout selection prior to actually editing a node.
panels_renderer_ipe::ajax_change_layout in panels_ipe/plugins/display_renderers/panels_renderer_ipe.class.php
AJAX entry point to create the controller form for an IPE.

File

includes/common.inc, line 562
Functions used by more than one panels client module.

Code

function panels_common_print_layout_links($layouts, $base_path, $link_options = array(), $current_layout = NULL) {
  $output = '';
  $categories = array();
  ctools_include('cleanstring');
  $default_category = '';
  foreach ($layouts as $id => $layout) {
    $category = ctools_cleanstring($layout['category']);
    $categories[$category] = $layout['category'];
    if ($id == $current_layout) {
      $default_category = $category;
    }
    $options[$category][$id] = panels_print_layout_link($id, $layout, $base_path . '/' . $id, $link_options, $current_layout);
  }
  $form = array();
  $form['categories'] = array(
    '#title' => t('Category'),
    '#type' => 'select',
    '#options' => $categories,
    '#name' => 'categories',
    '#id' => 'edit-categories',
    '#value' => $default_category,
    '#parents' => array(
      'categories',
    ),
    '#access' => count($categories) > 1 ? TRUE : FALSE,
  );
  $output .= drupal_render($form);
  $output .= '<div class="panels-choose-layout panels-layouts-checkboxes clearfix">';

  // We're doing these dependencies completely manualy, which is unusual, but
  // the process code only supports doing them in a form.
  // @todo modify dependent.inc to make this easier.
  $dependencies = array();
  foreach ($options as $category => $links) {
    $dependencies['panels-layout-category-' . $category] = array(
      'values' => array(
        'edit-categories' => array(
          $category,
        ),
      ),
      'num' => 1,
      'type' => 'hide',
    );
    $output .= '<div id="panels-layout-category-' . $category . '-wrapper">';
    $output .= '<div id="panels-layout-category-' . $category . '" class="form-checkboxes clearfix">';
    $output .= count($categories) > 1 ? '<div class="panels-layouts-category">' . $categories[$category] . '</div>' : '';
    foreach ($links as $key => $link) {
      $output .= $link;
    }
    $output .= '</div></div>';
  }
  $output .= '</div>';
  ctools_add_js('dependent');
  $js['CTools']['dependent'] = $dependencies;
  drupal_add_js($js, 'setting');
  return $output;
}