You are here

function page_manager_handler_add_form in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 page_manager/page_manager.admin.inc \page_manager_handler_add_form()

Provide a consistent UI for adding handlers.

2 calls to page_manager_handler_add_form()
page_manager_handler_add in page_manager/page_manager.admin.inc
Add a new task handler.
page_manager_page_form_basic in page_manager/plugins/tasks/page.admin.inc
Basic settings form for a page manager page.

File

page_manager/page_manager.admin.inc, line 1390
Administrative functions for the page manager.

Code

function page_manager_handler_add_form($form, $form_state, $features = array()) {
  $task = $form_state['task'];
  $task_handler_plugins = page_manager_get_task_handler_plugins($task);
  if (empty($task_handler_plugins)) {
    drupal_set_message(t('There are currently no variants available and a page may not be added. Perhaps you need to install the Panels module to get a variant?'), 'error');
    $form['buttons']['return']['#disabled'] = TRUE;
    return;
  }
  foreach ($task_handler_plugins as $id => $plugin) {
    $options[$id] = $plugin['title'];
    if (isset($plugin['add features'])) {
      $features[$id] = $plugin['add features'];
    }
  }
  if (!isset($form_state['type']) || $form_state['type'] != 'add') {
    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => t('Title'),
      '#description' => t('Administrative title of this variant. If you leave blank it will be automatically assigned.'),
    );
    $form['name'] = array(
      '#type' => 'machine_name',
      '#title' => t('Machine name'),
      '#required' => FALSE,
      '#description' => t("A unique machine-readable name for this variant. It must only contain lowercase letters, numbers, and underscores. This name will be used when exporting the variant. If left empty the variant's name will be used instead."),
      '#size' => 32,
      '#maxlength' => 32,
      '#machine_name' => array(
        'exists' => 'page_manager_handler_check_machine_name',
        'source' => array(
          'title',
        ),
      ),
      '#field_prefix' => '<span dir="ltr">' . $form_state['task_name'] . '__',
      '#field_suffix' => '</span>&lrm;',
    );
  }
  $form['handler'] = array(
    '#title' => t('Variant type'),
    '#type' => 'select',
    '#options' => $options,
  );

  // This set of checkboxes is not dangerous at all.
  $form['features'] = array(
    '#type' => 'item',
    '#title' => t('Optional features'),
    '#description' => t('Check any optional features you need to be presented with forms for configuring them. If you do not check them here you will still be able to utilize these features once the new page is created. If you are not sure, leave these unchecked.'),
    '#tree' => TRUE,
  );
  ctools_include('dependent');
  foreach ($features as $plugin => $feature_list) {
    foreach ($feature_list as $feature_id => $feature) {
      $form['features'][$plugin][$feature_id] = array(
        '#type' => 'checkbox',
        '#title' => $feature,
      );
      if (!empty($form_state['page']->forms) && in_array($feature_id, $form_state['page']->forms)) {
        $form['features'][$plugin][$feature_id]['#default_value'] = TRUE;
      }
      if ($plugin != 'default') {
        $form['features'][$plugin][$feature_id] += array(
          '#dependency' => array(
            'edit-handler' => array(
              $plugin,
            ),
          ),
        );
      }
    }
  }
  return $form;
}