You are here

public function FivestarForm::submitForm in Fivestar 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

src/Form/FivestarForm.php, line 115

Class

FivestarForm
Fivestar form.

Namespace

Drupal\fivestar\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $context = $form_state
    ->get('context');
  if (isset($context['entity'])) {
    $entity = $context['entity'];
    $fivestar_field_name = $context['field_definition']
      ->getName();
    if ($entity
      ->hasField($fivestar_field_name)) {

      // For votingapi value will be save during save rating value to
      // field storage.
      $entity
        ->set($fivestar_field_name, $form_state
        ->getValue('vote'));
      $entity
        ->save();
    }
  }
  $form_state
    ->setRebuild(TRUE);
}