You are here

function votingapi_reaction_form_vote_type_form_submit in Voting API Reaction 8

Custom submit handler for vote type form.

Parameters

array $form: The form to process.

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

Throws

\Drupal\Core\Entity\EntityStorageException

1 string reference to 'votingapi_reaction_form_vote_type_form_submit'
votingapi_reaction_form_alter in ./votingapi_reaction.module
Implements hook_form_alter().

File

./votingapi_reaction.module, line 147
Allows users to react to any entity using Voting and Field APIs.

Code

function votingapi_reaction_form_vote_type_form_submit(array &$form, FormStateInterface $form_state) {
  $form_file = $form_state
    ->getValue('new', 0);

  /* @var \Drupal\votingapi\Entity\VoteType $entity */
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  $entity
    ->setThirdPartySetting('votingapi_reaction', 'reaction', $form_state
    ->getValue('reaction'));

  // Delete current icon if needed.
  if (!empty($form_file[0]) || $form_state
    ->getValue('remove')) {
    $icon = $entity
      ->getThirdPartySetting('votingapi_reaction', 'icon');
    if ($icon && ($file = File::load($icon))) {
      $file
        ->delete();
    }
  }

  // Save new icon if provided.
  if (!empty($form_file[0]) && ($file = File::load($form_file[0]))) {
    $file
      ->setPermanent();
    $file
      ->save();
    $entity
      ->setThirdPartySetting('votingapi_reaction', 'icon', $file
      ->id());
  }
  $entity
    ->save();
}