DEV Community

Filimonov
Filimonov

Posted on

Poll in Drupal 8

Install module Poll:

composer require drupal/poll ; drush en poll -y
Enter fullscreen mode Exit fullscreen mode

Go to the "Contents" page → "Polls":

/admin/content/poll
Enter fullscreen mode Exit fullscreen mode

Image description

Click "Add a poll" and add a new poll.

Image description

Write a question and answer options. Change the author, if necessary. Check all the boxes.

  • Active - the poll is on, you can vote in it;
  • Poll Duration - time during which the poll will be active;
  • Allow anonymous votes - unregistered users will be able to vote;
  • Allow cancel votes - you can cancel your choice and vote again;
  • Allow view results - you can see the results of the poll, and not vote.

Save.

Separate pages are created for polls. Since this is the first poll on my site, it will have a path:

/poll/1
Enter fullscreen mode Exit fullscreen mode

But you don't want polls as separate pages, but as part of the content of other pages.
That's why it's more convenient to create a paragraph with a "poll" field in it.

Find the "Link" subsection and click on "Other..."<br>

In the "Material" subsection, there will be a "Survey"

In display management, change the output format to "Entity Ready to Output":

Image description

Attach this paragraph to the material type field, or any other entity where you need to output a survey and add it through the autocomplete field.

We get the result:

I attached the survey to a paragraph field of the "News" material type.

Top comments (0)