You are here

function custom_breadcrumbs_panels_form in Custom Breadcrumbs 6.2

Same name and namespace in other branches
  1. 7.2 custom_breadcrumbs_panels/custom_breadcrumbs_panels.module \custom_breadcrumbs_panels_form()

Form builder; Displays an edit form for a panels breadcrumb.

See also

custom_breadcrumbs_form_validate()

custom_breadcrumbs_form_submit()

1 string reference to 'custom_breadcrumbs_panels_form'
custom_breadcrumbs_panels_menu in custom_breadcrumbs_panels/custom_breadcrumbs_panels.module
Implements hook_menu().

File

custom_breadcrumbs_panels/custom_breadcrumbs_panels.module, line 205

Code

function custom_breadcrumbs_panels_form(&$form_state, $type) {
  $form = array();
  $breadcrumb = NULL;
  $bid = arg(5);
  if (isset($bid)) {
    drupal_set_title(t('Edit Custom Breadcrumb for Panel Page'));
    $breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_panels', NULL, array(
      'bid' => $bid,
    ));
    $breadcrumb = array_pop($breadcrumbs);
  }
  else {
    drupal_set_title(t('Add Custom Breadcrumb for Panel Page'));
  }
  $options = array();
  $tasks = page_manager_get_tasks_by_type('page');
  $pages = array(
    'operations' => array(),
  );
  page_manager_get_pages($tasks, $pages);
  foreach ($pages['rows'] as $id => $info) {

    // Build optgroups for pages with multiple variants. Show admin titles for
    // pages & variants.
    $task = page_manager_get_page_cache($id);
    $title = decode_entities($task->subtask['admin title']);
    if (count($task->handlers) > 1) {
      $options[$title] = array(
        $id => t('!title (All variants)', array(
          '!title' => $title,
        )),
      );
      foreach ($task->handlers as $handler) {
        $options[$title][$handler->name] = decode_entities($handler->conf['title']);
      }
    }
    else {
      $handler = reset($task->handlers);

      // The ID stored must be the ID of the variant, but we use the page admin
      // title since this is often more helpful when there's only one variant.
      $options[$handler->name] = $title;
    }
  }
  $form['panel_id'] = array(
    '#type' => 'select',
    '#title' => t('Custom Panel Page'),
    '#required' => TRUE,
    '#options' => $options,
    '#description' => t('The Panel variant (or page) that this custom breadcrumb trail will apply to. If you want to apply the custom breadcrumb trail to all variants of a Panel page, choose the \'All variants\' option for that page.'),
    '#default_value' => isset($breadcrumb->panel_id) ? $breadcrumb->panel_id : NULL,
    '#weight' => -10,
  );

  // Store information needed to save this breadcrumb.
  $form['#module'] = 'custom_breadcrumbs_panels';
  $form['#infokey'] = 'panels';
  $form += custom_breadcrumbs_common_form_elements($bid, $breadcrumb);
  $form['visibility_php']['#description'] = t('Determine whether this breadcrumb should be displayed by using a snippet of PHP to return TRUE or FALSE. Do not use opening and closing php tags.');
  $form['#submit'][] = 'custom_breadcrumbs_form_submit';
  $form['#validate'][] = 'custom_breadcrumbs_form_validate';
  return $form;
}