function paragraphs_admin_bundle_form_submit in Paragraphs 7
Submit handler for paragraphs_admin_bundle_form().
Parameters
array $form: The form structure array.
array $form_state: An associative array containing the current state of the form.
See also
paragraphs_admin_bundle_form()
File
- ./
paragraphs.admin.inc, line 215 - Admin functions for the paragraphs module.
Code
function paragraphs_admin_bundle_form_submit(array $form, array &$form_state) {
$bundle = new stdClass();
if (!$form_state['values']['locked']) {
$bundle->bundle = trim($form_state['values']['bundle']);
}
else {
$bundle->bundle = $form['#paragraphs_bundle']->bundle;
}
$bundle->locked = 1;
$bundle->name = trim($form_state['values']['name']);
// Set bundle label equal to name if empty.
$bundle->label = empty($form_state['values']['label']) ? $bundle->name : trim($form_state['values']['label']);
$bundle->description = trim($form_state['values']['description']);
$variables = $form_state['values'];
// Remove everything that's been saved already - whatever's left is assumed
// to be a persistent variable.
foreach ($variables as $key => $value) {
if (isset($bundle->{$key})) {
unset($variables[$key]);
}
}
unset($variables['form_token'], $variables['op'], $variables['submit'], $variables['delete'], $variables['reset'], $variables['form_id'], $variables['form_build_id']);
$status = paragraphs_bundle_save($bundle);
$t_args = array(
'%name' => $bundle->name,
);
if ($status == SAVED_UPDATED) {
drupal_set_message(t('The paragraph bundle %name has been updated.', $t_args));
}
elseif ($status == SAVED_NEW) {
drupal_set_message(t('The paragraph bundle %name has been added.', $t_args));
watchdog('paragraphs', 'Added paragraph bundle %name.', $t_args, WATCHDOG_NOTICE, l(t('view'), 'admin/structure/paragraphs'));
}
$form_state['redirect'] = 'admin/structure/paragraphs';
}