diff --git a/poll.install b/poll.install index 20fa756..790e1d8 100644 --- a/poll.install +++ b/poll.install @@ -125,3 +125,17 @@ function poll_update_8001() { $field_schema['poll__choice']['indexes']['choice_target_id'] = ['choice_target_id']; \Drupal::keyValue('entity.storage_schema.sql')->set('poll.field_schema_data.choice', $field_schema); } + +/** + * Add new field to poll_choice table. + */ +function poll_update_8002() { + $spec = [ + 'type' => 'int', + 'description' => "Fake Votes", + 'length' => 10, + 'not null' => FALSE, + ]; + $schema = \Drupal::database()->schema(); + $schema->addField('poll_choice', 'fake_votes', $spec); +} diff --git a/src/Form/PollForm.php b/src/Form/PollForm.php index fa252cd..52d3d2e 100644 --- a/src/Form/PollForm.php +++ b/src/Form/PollForm.php @@ -60,6 +60,15 @@ class PollForm extends ContentEntityForm { $insert = (bool) $poll->id(); $poll->save(); if ($insert) { + $choices = $poll->get('choice')->getValue(); + foreach ($choices as $choice) { + $query = \Drupal::database()->update('poll_choice'); + $query->fields([ + 'fake_votes' => $choice['fake_votes'], + ]); + $query->condition('id', $choice['target_id']); + $query->execute(); + } $this->messenger()->addMessage($this->t('The poll %poll has been updated.', array('%poll' => $poll->label()))); } else { diff --git a/src/Plugin/Field/FieldWidget/PollChoiceDefaultWidget.php b/src/Plugin/Field/FieldWidget/PollChoiceDefaultWidget.php index 8036682..8d1eb0c 100644 --- a/src/Plugin/Field/FieldWidget/PollChoiceDefaultWidget.php +++ b/src/Plugin/Field/FieldWidget/PollChoiceDefaultWidget.php @@ -63,6 +63,21 @@ class PollChoiceDefaultWidget extends WidgetBase { '#default_value' => $choice ? $choice->choice->value : NULL, '#prefix' => '