function rate_widget_form_submit in Rate 6.2
Same name and namespace in other branches
- 7 rate.admin.inc \rate_widget_form_submit()
Form submit handler.
File
- ./
rate.admin.inc, line 548 - Rating admin
Code
function rate_widget_form_submit($form, &$form_state) {
if ($form_state['clicked_button']['#id'] == 'edit-add-another') {
$form_state['rebuild'] = TRUE;
return $form_state['values'];
}
$widget = new stdClass();
$widget->name = $form_state['values']['name'];
$widget->tag = $form_state['values']['tag'];
$widget->title = $form_state['values']['title'];
$widget->node_types = array();
$widget->comment_types = array();
$widget->options = array();
$widget->template = $form_state['values']['widget_template'];
$widget->node_display = $form_state['values']['node_display'];
$widget->teaser_display = (bool) $form_state['values']['teaser_display'];
$widget->comment_display = $form_state['values']['comment_display'];
$widget->node_display_mode = $form_state['values']['node_display_mode'];
$widget->teaser_display_mode = $form_state['values']['teaser_display_mode'];
$widget->comment_display_mode = $form_state['values']['comment_display_mode'];
$widget->roles = $form_state['values']['roles'];
$widget->allow_voting_by_author = $form_state['values']['allow_voting_by_author'];
$widget->noperm_behaviour = $form_state['values']['noperm_behaviour'];
$widget->displayed = $form_state['values']['displayed'];
$widget->displayed_just_voted = $form_state['values']['displayed_just_voted'];
if ($widget->template != 'custom') {
// Take over the values from the template.
$template = _rate_get_template($widget->template);
if (!$template->customizable) {
$widget->options = $template->options;
}
$widget->value_type = $template->value_type;
!isset($template->theme) or $widget->theme = $template->theme;
!isset($template->css) or $widget->css = $template->css;
!isset($template->js) or $widget->js = $template->js;
$widget->translate = $template->translate;
if (isset($form_state['values']['translate'])) {
$widget->translate = (bool) $form_state['values']['translate'];
}
}
else {
$widget->value_type = $form_state['values']['value_type'];
$widget->translate = (bool) $form_state['values']['translate'];
}
foreach ($form_state['values'] as $name => $value) {
if (preg_match('/^value([0-9]+)$/', $name, $match) && preg_match('/^\\-?[0-9]+$/', $value)) {
$widget->options[] = array(
$value,
$form_state['values']['label' . $match[1]],
);
}
if (preg_match('/^node_type_(.+)$/', $name, $match) && $value) {
$widget->node_types[] = $match[1];
}
if (preg_match('/^comment_type_(.+)$/', $name, $match) && $value) {
$widget->comment_types[] = $match[1];
}
}
// Let other modules alter the rate widget.
foreach (module_implements('rate_widget') as $module) {
$hook = "{$module}_rate_widget";
$op = empty($form['#widget_id']) ? 'insert' : 'update';
$hook($op, $widget, $form_state['values']);
}
// Save the widget.
$widgets = variable_get(RATE_VAR_WIDGETS, array());
if (!empty($form['#widget_id'])) {
$id = (int) $form['#widget_id'];
}
else {
$id = 1;
while (isset($widgets[$id])) {
++$id;
}
}
$widgets[$id] = $widget;
variable_set(RATE_VAR_WIDGETS, $widgets);
drupal_set_message(t('The widget has been saved.'));
$form_state['redirect'] = RATE_PATH_ADMIN_PAGE;
}