public function BaseRatingForm::ajaxSubmit in Votingapi Widgets 8
Ajax submit handler.
File
- src/
Form/ BaseRatingForm.php, line 187
Class
- BaseRatingForm
- Form controller for Campaign edit forms.
Namespace
Drupal\votingapi_widgets\FormCode
public function ajaxSubmit(array $form, FormStateInterface $form_state) {
$this
->save($form, $form_state);
$settings = $form_state
->get('settings');
$result_function = $this
->getResultFunction($form_state);
$plugin = $form_state
->get('plugin');
$entity = $this
->getEntity();
$result_value = $this
->getResults($result_function, TRUE);
$form['value']['#attributes']['data-show-own-vote'] = 'true';
$form['value']['#default_value'] = (int) $entity
->getValue();
if ($settings['show_own_vote'] === '0') {
$form['value']['#attributes']['data-show-own-vote'] = 'false';
$form['value']['#default_value'] = $result_value;
}
$form['value']['#attributes']['data-vote-value'] = $entity
->getValue();
$form['value']['#attributes']['data-result-value'] = $result_value;
if ($settings['show_results'] === '1') {
$form['result']['#children']['result'] = $plugin
->getVoteSummary($entity);
}
if (!$plugin
->canVote($entity)) {
$form['value']['#attributes']['disabled'] = 'disabled';
}
$form_state
->setRebuild(TRUE);
return $form;
}