function panels_ajax_bootstrap_edit_remove in Panels Bootstrap Layout Builder 7.3
Same name and namespace in other branches
- 7 plugins/layouts/bootstrap/bootstrap.inc \panels_ajax_bootstrap_edit_remove()
AJAX responder to remove an existing row, column or region from a bootstrap layout.
1 string reference to 'panels_ajax_bootstrap_edit_remove'
- bootstrap.inc in plugins/
layouts/ bootstrap/ bootstrap.inc
File
- plugins/
layouts/ bootstrap/ bootstrap.inc, line 1720
Code
function panels_ajax_bootstrap_edit_remove($handler, $id) {
$settings =& $handler->display->layout_settings;
panels_bootstrap_convert_settings($settings, $handler->plugins['layout']);
if (empty($settings['items'][$id])) {
ajax_render_error(t('Invalid item id.'));
}
$item =& $settings['items'][$id];
$css_id = isset($handler->display->css_id) ? $handler->display->css_id : '';
// Create a renderer object so we can render our new stuff.
$renderer = panels_bootstrap_create_renderer(TRUE, $css_id, array(), $settings, $handler->display, $handler->plugins['layout'], $handler);
$siblings =& $settings['items'][$item['parent']]['children'];
$parent_class = '.' . $renderer->base[$settings['items'][$item['parent']]['type']] . '-' . $item['parent'];
// Find the offset of our array. This will also be the key because
// this is a simple array.
$offset = array_search($id, $siblings);
// Only bother with this stuff if our item is fluid, since fixed is
// as fixed does.
if ($item['type'] != 'row') {
if (isset($siblings[$offset + 1])) {
$next = $siblings[$offset + 1];
}
if (isset($siblings[$offset - 1])) {
$prev = $siblings[$offset - 1];
}
// Not sure what happens if they both failed. Maybe nothing.
}
// Remove the item.
array_splice($siblings, $offset, 1);
unset($settings['items'][$id]);
// Save our new state.
panels_edit_cache_set($handler->cache);
$class = $renderer->base[$item['type']] . '-' . $id;
$output = array();
$output[] = ajax_command_remove('#panels-dnd-main .' . $class);
// Regenerate the CSS for siblings.
if (!empty($siblings)) {
// Get all the CSS necessary for the entire row (as width adjustments may
// have cascaded).
$css = array();
foreach ($css as $selector => $data) {
$output[] = ajax_command_css($selector, $data);
}
}
// There are potentially two splitters linked to this item to be removed.
if (!empty($prev)) {
$output[] = ajax_command_remove('.bootstrap-splitter-for-' . $renderer->base[$item['type']] . '-' . $prev);
}
// Try to remove the 'next' one even if there isn't a $next.
$output[] = ajax_command_remove('.bootstrap-splitter-for-' . $renderer->base[$item['type']] . '-' . $id);
if (!empty($prev) && !empty($next)) {
// Add a new splitter that links $prev and $next:
$prev_class = '#panels-dnd-main .' . $renderer->base[$item['type']] . '-' . $prev;
$output[] = ajax_command_after($prev_class, $splitter);
// Send our fix height command.
$output[] = array(
'command' => 'bootstrap_fix_height',
);
}
// Rerender our parent item links:
$output[] = ajax_command_replace('.bootstrap-links-' . $item['parent'], panels_bootstrap_render_item_links($renderer, $item['parent'], $settings['items'][$item['parent']]));
$output[] = array(
'command' => 'bootstrap_fix_firstlast',
'selector' => $parent_class . '-inside',
'base' => 'panels-bootstrap-' . $item['type'],
);
$handler->commands = $output;
}