You are here

function panels_content_config_form in Panels 5.2

Same name and namespace in other branches
  1. 6.2 includes/display-edit.inc \panels_content_config_form()

Master FAPI definition for all pane add/edit configuration forms.

Parameters

object $cache: The $cache object for the panels $display currently being edited.

object $pane: The $pane object currently being added/edited.

bool $add: A boolean indicating whether we are adding a new pane ($add === TRUE) operation in this operation, or editing an existing pane ($add === FALSE).

Return value

array $form A structured FAPI form definition, having been passed through all the appropriate content-type specific callbacks.

2 string references to 'panels_content_config_form'
panels_ajax_add_config in includes/display_edit.inc
Entry point for AJAX: Add pane configuration.
panels_ajax_configure in includes/display_edit.inc
Entry point for AJAX: Edit pane configuration.

File

includes/display_edit.inc, line 1014

Code

function panels_content_config_form($cache, $pane, $add = FALSE) {
  $op = $add ? 'add' : 'edit';

  // for brevity and readability.
  $cc = $cache->content_config[$pane->pid];
  $form['start_form'] = array(
    '#value' => '<div class="modal-form">',
  );
  $form['configuration'] = panels_ct_conf_form($cc['ct_data'], $cache->display->context, $pane->configuration);
  if (is_array($form_additions = panels_ct_pane_config_form($pane, $cache->display->context, array(
    'configuration',
  ), $op))) {
    $form['configuration'] += $form_additions;
  }
  $form['configuration']['#tree'] = TRUE;
  if (!$cc['ignore_roles']) {
    if (user_access('administer pane access')) {
      $rids = array();
      $result = db_query("SELECT r.rid, r.name FROM {role} r ORDER BY r.name");
      while ($obj = db_fetch_object($result)) {
        $rids[$obj->rid] = $obj->name;
      }
      $form['access'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Access'),
        '#default_value' => $add ? array() : $pane->access,
        '#options' => $rids,
        '#description' => t('Only the checked roles will be able to see this pane; if no roles are checked, access will not be restricted.'),
      );
    }
    else {
      $form['access'] = array(
        '#type' => 'value',
        '#value' => isset($pane->access) ? $pane->access : array(),
      );
    }
  }
  if (isset($cc['visibility_controller'])) {
    $form['visibility'] = $cc['visibility_controller']($cache->display->context, $pane->subtype, $pane->configuration, $add);
  }
  $form['end_form'] = array(
    '#value' => '</div>',
  );
  $form['next'] = array(
    '#type' => 'submit',
    '#value' => $add ? t('Add pane') : t('Save'),
  );
  $form['vars'] = array(
    '#type' => 'value',
    '#value' => array(
      $cache,
      $pane,
      $add,
      $op,
    ),
  );

  // Allows content types that define this callback to have full control over the pane config form.
  if (isset($cc['form_controller'])) {
    call_user_func_array($cc['form_controller'], array(
      &$form,
      &$cache->content_config[$pane->pid],
      &$cache->display,
      $add,
    ));

    // Only set the cache with any new vars on the render passthrough; setting
    // it again could, depending on the changes in the plugin function, cause
    // serious data consistency problems.
    if (!isset($_POST['form_id'])) {
      panels_cache_set($cache->display->did, $cache);
    }
  }
  return $form;
}