Skip to content
Snippets Groups Projects

#2746713 - Multiple choice poll

3 open threads

Files

+ 25
0
@@ -212,6 +212,14 @@ class Poll extends ContentEntityBase implements EntityPublishedInterface, PollIn
return $this;
}
/**
* {@inheritdoc}
*/
public function getAnswerType(): string {
$answer_type = $this->get('answer_type')->value;
return empty($answer_type) ? PollInterface::ANSWER_TYPE_SINGLE : $answer_type;
}
/**
* {@inheritdoc}
*/
@@ -349,6 +357,23 @@ class Poll extends ContentEntityBase implements EntityPublishedInterface, PollIn
])
->setDisplayConfigurable('form', TRUE);
$fields['answer_type'] = BaseFieldDefinition::create('list_string')
->setLabel(t('Answer Type'))
->setDescription(t('Choose if user can select single or multiple answers.'))
->setSetting('allowed_values', [
PollInterface::ANSWER_TYPE_SINGLE => t('Single Answer'),
PollInterface::ANSWER_TYPE_MULTIPLE => t('Multiple Answers'),
])
->setDefaultValue(PollInterface::ANSWER_TYPE_SINGLE)
->setRequired(TRUE)
->setDisplayOptions('form', [
'type' => 'options_select',
'settings' => [
'display_label' => TRUE,
],
'weight' => 1,
]);
$fields['anonymous_vote_allow'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Allow anonymous votes'))
->setDescription(t('A flag indicating whether anonymous users are allowed to vote.'))
Loading