Form submission handler for forum_form_forum() and forum_form_container().
function forum_form_submit($form, &$form_state) {
$config = config('forum.settings');
if ($form['form_id']['#value'] == 'forum_form_container') {
$container = TRUE;
$type = t('forum container');
}
else {
$container = FALSE;
$type = t('forum');
}
// @todo Set explicit entity properties instead of arbitrary form values.
form_state_values_clean($form_state);
$term = entity_create('taxonomy_term', $form_state['values']);
$status = taxonomy_term_save($term);
switch ($status) {
case SAVED_NEW:
if ($container) {
$containers = $config
->get('containers');
$containers[] = $term->tid;
$config
->set('containers', $containers)
->save();
}
$form_state['values']['tid'] = $term->tid;
drupal_set_message(t('Created new @type %term.', array(
'%term' => $form_state['values']['name'],
'@type' => $type,
)));
break;
case SAVED_UPDATED:
drupal_set_message(t('The @type %term has been updated.', array(
'%term' => $form_state['values']['name'],
'@type' => $type,
)));
// Clear the page and block caches to avoid stale data.
cache_invalidate_tags(array(
'content' => TRUE,
));
break;
}
$form_state['redirect'] = 'admin/structure/forum';
}