You are here

public function RateWidgetBaseForm::save in Rate 8.2

Form submission handler for the 'save' action.

Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.

Parameters

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

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

Return value

int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.

Overrides EntityForm::save

1 call to RateWidgetBaseForm::save()
RateWidgetBaseForm::ajaxSubmit in src/Form/RateWidgetBaseForm.php
Ajax submit handler.

File

src/Form/RateWidgetBaseForm.php, line 551

Class

RateWidgetBaseForm
Form controller for rate vote forms.

Namespace

Drupal\rate\Form

Code

public function save(array $form, FormStateInterface $form_state, $display_readonly = FALSE, $deadline_disabled = FALSE) {
  $entity = $this
    ->getEntity();
  $plugin = $form_state
    ->get('plugin');
  $is_bot_vote = $plugin
    ->isBotVote();
  if ($plugin
    ->canVote($entity) && !$is_bot_vote) {
    if ($display_readonly === FALSE || ($deadline_disabled = FALSE)) {
      $return = parent::save($form, $form_state);

      // @todo: Could be simplified if https://www.drupal.org/project/votingapi/issues/3159592 was done.
      $voted_entity_id = $entity
        ->getVotedEntityId();
      $voted_entity_type_id = $entity
        ->getVotedEntityType();
      $voted_entity = $this->entityTypeManager
        ->getStorage($voted_entity_type_id)
        ->load($voted_entity_id);
      Cache::invalidateTags([
        'vote:' . $voted_entity
          ->bundle() . ':' . $voted_entity_id,
      ]);
      return $return;
    }
  }
  return FALSE;
}