You are here

function panels_page_admin_view in Panels 6.2

Same name and namespace in other branches
  1. 5.2 panels_page/panels_page.admin.inc \panels_page_admin_view()

File

panels_page/panels_page.admin.inc, line 875
panels_page.admin.inc

Code

function panels_page_admin_view(&$form_state) {
  $panel_page =& $form_state['panel_page'];
  $args = $form_state['args'];
  $form = array();
  $form['fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Administrative preview: enter arguments'),
    '#collapsible' => TRUE,
  );
  $required_args = strpos($panel_page->path, '%') === false ? 0 : count(split($panel_page->path, '%'));
  $url = panels_page_get_url($panel_page, $args);
  if ($args_missing = max($required_args - count($args), 0)) {
    $value = $url;
    $description = format_plural($args_missing, '1 argument is missing to generate a valid URL.', '@count arguments are missing to generate a valid URL.');
  }
  else {
    $value = l($url, $url);
    $description = t('Click to see the real panel page.');
  }
  $form['fieldset']['url'] = array(
    '#type' => 'item',
    '#title' => t('Real panel URL'),
    '#value' => $value,
    '#description' => $description,
  );
  $contexts = panels_context_load_contexts($panel_page);
  $count = 0;
  foreach ($contexts as $id => $context) {
    if (substr($id, 0, 8) == 'argument') {
      $required = $count + 1 <= $required_args ? TRUE : FALSE;
      $description = $required ? t('Required argument (occupies %-placeholder number !position)', array(
        '!position' => $count + 1,
      )) : t('Optional argument');
      $form['fieldset']["arg{$count}"] = array(
        '#type' => 'textfield',
        '#title' => check_plain($context->identifier),
        '#default_value' => isset($args[$count]) ? $args[$count] : '',
        '#required' => $required,
        '#description' => $description,
      );
    }
    if (isset($args[$count])) {
      unset($args[$count]);
    }
    $count++;
  }
  $add = '';
  if ($args) {
    $add = implode('/', $args);
  }
  $form['fieldset']['additional'] = array(
    '#type' => 'textfield',
    '#title' => t('Additional arguments'),
    '#description' => t('Separated by /'),
    '#default_value' => $add,
  );
  $form['fieldset']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Change arguments'),
  );
  $form['panel_page'] = array(
    '#type' => 'value',
    '#value' => $panel_page,
  );
  $form_state['contexts'] = $contexts;
  return $form;
}