function panels_edit_form in Panels 5
Edit an already loaded panels.
2 string references to 'panels_edit_form'
- panels_add_page in ./
panels.module - Handle the add panels page
- panels_edit_page in ./
panels.module
File
- ./
panels.module, line 295
Code
function panels_edit_form($panels) {
drupal_add_css(drupal_get_path('module', 'panels') . '/panels_admin.css');
$layouts = panels_get_layouts();
$layout = $layouts[$panels->layout];
$content_types = panels_get_content_types();
// Process all our add button stuff first so we can add stuff to the
// form semi dynamically.
$form['add'] = array(
'#type' => 'fieldset',
'#title' => t('Add content'),
'#collapsible' => false,
'#description' => t('Select an area to add content to, then select a type of content and click the appropriate button. The content will be added.'),
);
// Drop the array keys into a temporary in order to protect references.
$temp = array_keys($layout['content areas']);
$default_radio = array_shift($temp);
$form['add']['area'] = array(
'#type' => 'radios',
'#title' => t('Area'),
'#options' => $layout['content areas'],
'#prefix' => '<div class="container-inline">',
'#suffix' => '</div>',
'#default_value' => $default_radio,
);
foreach ($content_types as $id => $type) {
$function = $type['admin'];
if (function_exists($function)) {
global $form_values;
$form['add'][$id] = $function('add button', $dummy);
// $dummy needed for cause you can't have default args on a reference.
$form['add'][$id]['#parents'] = array(
'add',
$id,
);
$form['add'][$id]['#tree'] = true;
panels_form_builder($form['add'][$id]);
if ($conf = $function('add', $form_values['add'][$id])) {
$add->configuration = $conf;
$add->type = $id;
$form['add']['area']['#parents'] = array(
'area',
);
panels_form_builder($form['add']['area']);
$add->area = $form_values['area'];
}
}
}
$form['layout'] = array(
'#type' => 'value',
'#value' => $panels->layout,
);
$form['did'] = array(
'#type' => 'value',
'#value' => $panels->did,
);
$form['info'] = array(
'#type' => 'fieldset',
'#title' => t('General information'),
'#collapsible' => false,
);
$file = panels_get_file_path($layout['module'], $layout['icon'], false);
$icon .= theme('image', $file);
$form['info']['layout-icon'] = array(
'#value' => '<div class="layout-icon">' . $icon . '</div>',
);
$form['info']['layout-display'] = array(
'#value' => '<strong>Layout</strong>: ' . $layout['title'],
);
$form['info']['title'] = array(
'#type' => 'textfield',
'#default_value' => $panels->title,
'#title' => t('Page title'),
'#description' => t('The page title for this panels layout'),
);
$form['info']['css_id'] = array(
'#type' => 'textfield',
'#default_value' => $panels->css_id,
'#title' => t('CSS ID'),
'#description' => t('The CSS ID to apply to this page'),
);
$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['info']['access'] = array(
'#type' => 'checkboxes',
'#title' => t('Access'),
'#default_value' => $panels->access,
'#options' => $rids,
'#description' => t('Only the checked roles will be able to see this panel in any form; if no roles are checked, access will not be restricted.'),
);
$form['info']['path'] = array(
'#type' => 'textfield',
'#default_value' => $panels->path,
'#title' => t('Path'),
'#description' => t('The URL path to give this page, i.e, path/to/page'),
'#required' => TRUE,
);
$form['content'] = array(
'#tree' => true,
);
// Go through our content areas and display what we have.
foreach ($layout['content areas'] as $area => $title) {
$list = array();
$form['content'][$area] = array(
'#tree' => true,
);
// Construct the order, feeding it the default order for what
// we know about. When we pull it back out, it may well be
// different due to past submits.
$order = array();
if (is_array($panels->content[$area])) {
$order = array_keys($panels->content[$area]);
}
$form['content'][$area]['order'] = array(
'#type' => 'hidden',
'#default_value' => serialize($order),
'#parents' => array(
'content',
$area,
'order',
),
);
// If an add button has added an item to the area, put it in and update
// the $order.
panels_form_builder($form['content'][$area]['order']);
$order = unserialize($form['content'][$area]['order']['#value']);
if ($add->area == $area) {
// say THIS 5 times real fast
if ($panels->content[$area] && $order) {
$position = max(max(array_keys($order)), max(array_keys($panels->content[$area]))) + 1;
}
else {
if ($order) {
$position = max(array_keys($order)) + 1;
}
else {
$position = 0;
}
}
$panels->content[$area][$position] = $add;
$order[] = $position;
$form['content'][$area]['order']['#value'] = serialize($order);
}
// Go through each item in the area and render it.
$count = count($order);
foreach ($order as $position => $id) {
// place buttons to re-order content.
$form['content'][$area][$id]['buttons'] = array(
'#parents' => array(
'content',
$area,
$id,
'buttons',
),
'#tree' => TRUE,
);
panels_add_buttons($form['content'][$area][$id]['buttons'], $count, $position);
// figure out if one of those buttons was pressed
panels_form_builder($form['content'][$area][$id]['buttons']);
$deleted = false;
foreach ($GLOBALS['form_values']['content'][$area][$id]['buttons'] as $button => $value) {
if ($value) {
$function = 'panels_move_' . $button;
$function($order, $position);
$form['content'][$area]['order']['#value'] = serialize($order);
if ($button == 'delete') {
$deleted = true;
}
}
}
// If a content item was deleted, it still has buttons. Get rid of them.
// It had buttons because we needed to give it buttons to see if its
// buttons were clicked.
if ($deleted) {
unset($form['content'][$area][$id]['buttons']);
}
else {
// we finally get to add the conent item's content to the form.
$area_record = $panels->content[$area][$id];
$form['content'][$area][$id]['type'] = array(
'#type' => 'hidden',
'#default_value' => $area_record->type,
'#parents' => array(
'content',
$area,
$id,
'type',
),
);
// retrieve what was already there -- so we can retain edits and
// content items that were added.
panels_form_builder($form['content'][$area][$id]['type']);
$type = $form['content'][$area][$id]['type']['#value'];
$function = $content_types[$type]['admin'];
if (function_exists($function)) {
$array = array(
'#tree' => true,
'#parents' => array(
'content',
$area,
$id,
'configuration',
),
);
$form['content'][$area][$id]['configuration'] = array_merge($array, $function('edit', $area_record->configuration, array(
'content',
$area,
$id,
'configuration',
)));
panels_form_builder($form['content'][$area][$id]['configuration']);
}
}
}
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}