- Issue created by @zenimagine
- 🇫🇷France Tritof
I join you in this request @zenimage.
In the meantime, I've used this piece of code that responded to the need. There is probably a better way to do it, but this works.
Basically, it compares current user roles with an array of roles that aren't allowed to vote. If there is any match, it removes the poll and just exposes the results instead./** * Implements hook_form_FORM_ID_alter for polls. */ function customer_specifics_form_poll_view_form_alter(&$form, FormStateInterface $form_state, $form_id): void { $currentUserRoles = \Drupal::currentUser()->getRoles(); $roles = ['role_1', 'role_2']; $diff = array_intersect($currentUserRoles, $roles); if(!empty($diff)) { $poll = \Drupal::entityTypeManager()->getStorage('poll')->load(substr($form_id, -1)); $pollViewForm = \Drupal::service('class_resolver')->getInstanceFromDefinition(PollViewForm::class); $results = $pollViewForm->showPollResults($poll); $form['choice'] = []; $form['actions'] = []; $form['results'] = $results; } }