function panels_flexible_add_item_form_submit in Panels 6.3
Same name and namespace in other branches
- 7.3 plugins/layouts/flexible/flexible.inc \panels_flexible_add_item_form_submit()
Submit handler for editing a flexible item.
File
- plugins/
layouts/ flexible/ flexible.inc, line 1478
Code
function panels_flexible_add_item_form_submit(&$form, &$form_state) {
$item =& $form_state['item'];
$parent =& $form_state['parent'];
$location =& $form_state['location'];
$settings =& $form_state['settings'];
$item['class'] = $form_state['values']['class'];
if ($item['type'] == 'region') {
$item['title'] = $form_state['values']['title'];
}
if ($item['type'] != 'row') {
$item['width_type'] = $form_state['values']['width_type'];
}
else {
$item['contains'] = $form_state['values']['contains'];
}
if ($item['type'] == 'region') {
// derive the region key from the title
$key = preg_replace("/[^a-z0-9]/", '_', drupal_strtolower($item['title']));
while (isset($settings['items'][$key])) {
$key .= '_';
}
$form_state['key'] = $key;
}
else {
$form_state['key'] = $key = max(array_keys($settings['items'])) + 1;
}
$form_state['sibling'] = NULL;
if ($item['type'] != 'row' && !empty($parent['children'])) {
// Figure out what the width should be and adjust our sibling if
// necessary.
if ($location == 'left') {
$form_state['sibling'] = reset($parent['children']);
}
else {
$form_state['sibling'] = end($parent['children']);
}
// If there is no sibling, or the sibling is of a different type,
// the default 100 will work for either fixed or fluid.
if ($form_state['sibling'] && $settings['items'][$form_state['sibling']]['width_type'] == $item['width_type']) {
// steal half of the sibling's space.
$width = $settings['items'][$form_state['sibling']]['width'] / 2;
$settings['items'][$form_state['sibling']]['width'] = $width;
$item['width'] = $width;
}
}
// Place the item.
$settings['items'][$key] = $item;
if ($location == 'left') {
array_unshift($parent['children'], $key);
}
else {
$parent['children'][] = $key;
}
}