Skip to content
Snippets Groups Projects

Issue #2984434 by tr, tamnv: Don't always show the average when the user hasn't voted

@@ -85,9 +85,9 @@ class BaseRatingForm extends ContentEntityForm {
'#options' => $options,
'#attributes' => [
'autocomplete' => 'off',
'data-result-value' => ($this->getResults($result_function)) ? $this->getResults($result_function) : -1,
'data-vote-value' => ($entity->getValue()) ? $entity->getValue() : (($this->getResults($result_function)) ? $this->getResults($result_function) : -1),
'data-style' => ($settings['style']) ? $settings['style'] : 'default',
'data-result-value' => $this->getResults($result_function) ?? -1,
'data-vote-value' => (int) $entity->getValue(),
'data-style' => $settings['style'] ?? 'default',
],
];
@@ -96,6 +96,7 @@ class BaseRatingForm extends ContentEntityForm {
if (!$settings['show_own_vote']) {
$form['value']['#attributes']['data-show-own-vote'] = 'false';
$form['value']['#attributes']['data-vote-value'] = $this->getResults($result_function) ?? -1;
$form['value']['#default_value'] = $this->getResults($result_function);
}
@@ -138,7 +139,7 @@ class BaseRatingForm extends ContentEntityForm {
*/
protected function getResultFunction(FormStateInterface $form_state) {
$entity = $this->getEntity();
return ($form_state->get('resultfunction')) ? $form_state->get('resultfunction') : 'vote_field_average:' . $entity->getVotedEntityType() . '.' . $entity->field_name->value;
return $form_state->get('resultfunction') ?? 'vote_field_average:' . $entity->getVotedEntityType() . '.' . $entity->field_name->value;
}
/**
Loading