You are here

public function VotingApiReactionForm::processForm in Voting API Reaction 8

Process callback: assigns weights and hides extra fields.

Overrides EntityForm::processForm

See also

\Drupal\Core\Entity\EntityForm::form()

File

src/Form/VotingApiReactionForm.php, line 173

Class

VotingApiReactionForm
Form implementation of the reaction form used in field formatter.

Namespace

Drupal\votingapi_reaction\Form

Code

public function processForm($element, FormStateInterface $form_state, $form) {

  // Prepare settings.
  $field_items = $form_state
    ->get('field_items');
  $settings = $form_state
    ->get('formatter_settings') + $field_items
    ->getSettings();

  // Try to get the last reaction.
  if ($entity = $this->reactionManager
    ->lastReaction($this->entity, $settings)) {
    $this->entity = $entity;
  }
  else {
    $this->entity = Vote::create([
      'type' => '',
      'entity_id' => $this->entity
        ->getVotedEntityId(),
      'entity_type' => $this->entity
        ->getVotedEntityType(),
      'value_type' => 'option',
      'value' => 1,
      'field_name' => $this->entity
        ->get('field_name')->value,
    ]);
  }
  return $element;
}