Monday, December 2, 2019

Drupal 8 - How To Add A Poll To A Drupal 8 Website

CentOS 7 / Drupal 8




How To Add A Poll To A Drupal 8 Website


The MMTM YouTube Channel is a powerful way to engage with people - but it doesn't go far enough!  We think an important strategy for building up a sustainable Subscribers base for My Man The Maker involves encouraging the existing Subscribers of other websites, like YouTube, to also Subscribe directly to mymanthemaker.com.  Of course, the overarching intention is to convert YouTube Subscribers into direct MMTM customers, with nobody in between - no matter how excellent they or their services may be.  Times can change, and without a direct connection to its own Subscribers and Customers, MMTM would always have a weakness.  A disruption to that 3rd party, planned or otherwise, could really hurt MMTM, perhaps fatally.


So, how can you go about attracting people from popular social media sites to your own website?  One time-proven way of increasing a connection with Subscribers is to increase interaction via Contests and Polls.  One of the easiest contests to run is a Poll, where you pose a question and then let people weigh in on what option (which you also provide) is their preferred choice.

Now, Drupal has featured Polls for as long as I can remember - at least since Drupal 6 - but I have never had occasion to use it.  Well, that situation has now changed!  I now urgently need to be able to run Polls for the purpose of rewarding people who came over from YouTube (or wherever else) to www.mymanthemaker.com so they could give their opinions and maybe win something.  In return, I am prepared to (maybe) give them a reward - via some kind of giveaway contest.  Also, while they are visiting the mymanthemaker.com website, I can do everything I can to convince them to buy something from its online store!

Polls on YouTube are called Cards, and they are a very powerful and popular way of engaging with people on YouTube.  The only problem is that when you use a YouTube Poll,. you only get limited flexibility and you lose the ability to do things with the user that YouTube may not have (or may never) implement.

First I needed to set the stage on YouTube, so what I did was mention the Poll live (in the video) as well as in the video description.  The video description featured a clear call to action for people to Subscribe to my YouTube channel, and then go over to mymanthemaker.com, register there as well and then vote in a Poll to have a chance to win!



Once I was done with YouTube, the next thing I needed to do was to extend the user definition in Drupal 8 by adding a custom field, YouTube Name to the user type.  

This is explained in great detail in another article entitled How To Add A Custom Field To Drupal 8's Create New Account Screen.  

The next piece of the puzzle was to install and enable a poll in Drupal 8.  The Poll Module for Drupal 8 is available at www.drupal.org, and here's an Overview and Features of the Drupal Poll Module:


Here's some Project information regarding the Drupal Poll Module:



Installing the Poll Module was quite simple and easy:  I just right-clicked on the tar.gz (41.25 KB) link in the Project Information area, copied the link address and then navigated to my Linux CLI and did the following:

# pwd
<drupal_root>/sites/all/modules

NOTE:  <drupal_root> is just a place holder for your location in the file system!

# wget https://ftp.drupal.org/files/projects/poll-8.x-1.3.tar.gz
--2019-12-02 19:09:03--  https://ftp.drupal.org/files/projects/poll-8.x-1.3.tar.gz
Resolving ftp.drupal.org (ftp.drupal.org)... 151.101.2.217, 151.101.66.217, 151.101.130.217, ...
Connecting to ftp.drupal.org (ftp.drupal.org)|151.101.2.217|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 42235 (41K) [application/octet-stream]
Saving to: ‘poll-8.x-1.3.tar.gz.1’

100%[======================================>] 42,235      --.-K/s   in 0.003s

2019-12-02 19:09:03 (11.8 MB/s) - ‘poll-8.x-1.3.tar.gz.1’ saved [42235/42235]


# tar -zxvf poll-8.x-1.3.tar.gz
poll/
poll/README.md
poll/config/
poll/config/install/
poll/config/install/core.entity_view_mode.poll.teaser.yml
poll/config/install/views.view.poll_admin.yml
poll/config/install/views.view.poll_list.yml
poll/css/
poll/css/poll.base-rtl.css
poll/css/poll.base.css
poll/css/poll.theme-rtl.css
poll/css/poll.theme.css
poll/js/
poll/js/poll.admin.js
poll/poll.info.yml
poll/poll.install
poll/poll.libraries.yml
poll/poll.links.action.yml
poll/poll.links.menu.yml
poll/poll.links.task.yml
poll/poll.module
poll/poll.permissions.yml
poll/poll.routing.yml
poll/poll.services.yml
poll/poll.tokens.inc
poll/src/
poll/src/Controller/
poll/src/Controller/PollController.php
poll/src/Entity/
poll/src/Entity/Poll.php
poll/src/Entity/PollChoice.php
poll/src/Form/
poll/src/Form/PollDeleteForm.php
poll/src/Form/PollForm.php
poll/src/Form/PollItemsDeleteForm.php
poll/src/Form/PollSettingsForm.php
poll/src/Form/PollViewForm.php
poll/src/Form/PollVoteDeleteForm.php
poll/src/Plugin/
poll/src/Plugin/Block/
poll/src/Plugin/Block/PollRecentBlock.php
poll/src/Plugin/Field/
poll/src/Plugin/Field/FieldWidget/
poll/src/Plugin/Field/FieldWidget/PollChoiceDefaultWidget.php
poll/src/Plugin/views/
poll/src/Plugin/views/field/
poll/src/Plugin/views/field/PollStatus.php
poll/src/Plugin/views/field/PollTotalVotes.php
poll/src/PollAccessControlHandler.php
poll/src/PollChoiceInterface.php
poll/src/PollChoiceTranslationHandler.php
poll/src/PollChoiceTranslationMetadataWrapper.php
poll/src/PollInterface.php
poll/src/PollListBuilder.php
poll/src/PollPostRenderCache.php
poll/src/PollStorage.php
poll/src/PollStorageInterface.php
poll/src/PollViewBuilder.php
poll/src/PollViewData.php
poll/src/PollVoteStorage.php
poll/src/PollVoteStorageInterface.php
poll/templates/
poll/templates/poll-meter.html.twig
poll/templates/poll-results.html.twig
poll/templates/poll-vote.html.twig
poll/tests/
poll/tests/src/
poll/tests/src/Functional/
poll/tests/src/Functional/PollBlockTest.php
poll/tests/src/Functional/PollCreateTest.php
poll/tests/src/Functional/PollDeleteChoiceTest.php
poll/tests/src/Functional/PollExpirationTest.php
poll/tests/src/Functional/PollFieldTest.php
poll/tests/src/Functional/PollFieldUITest.php
poll/tests/src/Functional/PollHtmlSpecialCharactersTest.php
poll/tests/src/Functional/PollListTest.php
poll/tests/src/Functional/PollTestBase.php
poll/tests/src/Functional/PollTokenReplaceTest.php
poll/tests/src/Functional/PollViewTest.php
poll/tests/src/Functional/PollVoteCheckHostnameTest.php
poll/tests/src/Functional/PollVoteMultilingualTest.php
poll/tests/src/Functional/PollVoteTest.php
poll/tests/src/FunctionalJavascript/
poll/tests/src/FunctionalJavascript/PollVoteJavascriptTest.php
poll/LICENSE.txt

With the Poll Module installed, I then used the Drupal 8 Administrator GUI to enable the module, by selecting it and then clicking on Install:


Once the Poll Module is was installed and enabled, a new content option (Polls), appeared in the Content area of the Drupal 8 Administrator GUI:


When I clicked on Polls, it led to an area where you can Add a poll:


I then used the provided form to construct a Poll regarding the Helmet Poll I wanted to run for a project I am working on, EZ-RIDER:


When I was finished, I clicked on SAVE.  

With the Poll constructed, I next needed to figure out where to show the Poll to my Authenticated users.  I figured the LEFT SIDEBAR would be a good place for that, so I navigated to HOME -> Administration -> Structure -> Block layout and decided to put the Most recent poll in Sidebar First.  

Considering that there is only one Poll at the moment, that seemed like a reasonable choice.


Finally, I wanted only Authenticated users, i.e. people who had gone through the Create an account process of www.mymanthemaker.com to be able to see the poll and vote, so I had to go to the area of the Drupal Administrative GUI that controlled Poll visibility and adjust the permissions accordingly:


Once I was in the right place, I adjusted the permissions so that only Authenticated users could see the Poll:


OK, with all of that done...time for some testing!

Will the poll show NOT show up for an Anonymous user?


Success!...but not quite finished yet...

Will the Poll I just created show up for an Authenticated user, like my test user?




REFERENCES:

https://www.drupal.org/project/poll

https://www.drupal.org/project/pollfield/issues/714924




No comments:

Post a Comment