You are here

function votingapi_reaction_install in Voting API Reaction 8

Implements hook_install().

File

./votingapi_reaction.install, line 11
Contains voting_reactions.install.

Code

function votingapi_reaction_install() {
  $reactions = _votingapi_reaction_get_reactions();
  $voteTypeStorage = \Drupal::service('entity_type.manager')
    ->getStorage('vote_type');

  // Create reactions.
  $voteTypes = $voteTypeStorage
    ->loadMultiple($voteTypeStorage
    ->getQuery()
    ->condition('id', array_keys($reactions), 'IN')
    ->execute());
  foreach ($reactions as $key => $label) {
    $voteType = empty($voteTypes[$key]) ? $voteTypeStorage
      ->create([
      'id' => $key,
      'label' => $label,
      'value_type' => 'points',
      'description' => 'Automatically created reaction',
    ]) : $voteTypes[$key];
    $voteType
      ->setThirdPartySetting('votingapi_reaction', 'reaction', TRUE);
    $voteType
      ->setThirdPartySetting('votingapi_reaction', 'icon', '');
    $voteType
      ->save();
  }
}