Monday, December 2, 2019

Drupal 8 - How To Add A Custom Field To Drupal 8's Create New Account Screen

CentOS 7 / Drupal 8


How To Add A Custom Field To Drupal 8's Create New Account Screen


One of the things that I would dearly love to do with my growing Tube Creator Channel (MY MAN THE MAKER) is to have the ability to give away prizes to my YouTube Subscribers via Contests and Polls.  

YouTube has a poll feature, but it doesn't do exactly what I want (encourage people to double-register at both YouTube and mymanthemaker.com, so I can increase engagement).  Now, polls have been a feature of Drupal for a very long time, since at least Drupal 6, but I have never had occasion to use them...until now!  

But before I can start giving away free prizes at mymanthemaker.com, I to put a means in place that ensures that whatever winner(s) get chosen, they are among my current YouTube Subscribers.  Part of setting up this functionality is to ask people what their YouTube Name is, as they are creating their new account at mymanthemaker.com.

Currently, the Create new account screen at mymanthemaker looks like this:


What I wanted to do was to add a custom field to the Create new account screen to people could suppy their YouTube Name at the time of account creation.

Turns out this task is fairly easy, and here's how I did it:

First I navigated to the Home -> Administration -> Configuration -> People area of the Drupal 8 Administration GUI, and then I clicked on Manage fields:


Next, I clicked on Add field:



Next, I Iselected Text (plain) as the field type and gave the field a meaningful name.  In my case, I chose to call the new field YouTube Name:



Next, I supplied some information about the the field, such as its Maximum length, and Allowed number of values.  In my case, I accepted the defaults:


Next, I provided some settings information for the new YouTube Name field, in particular I wrote Help Text that (I hope) explains the presence of this new field in the registration page:


Once I had finished supplying the information I clicked on Save settings.  I was then presented with these results:



Everything looked great!

I next navigated to www.mymanthemaker.com and clicked on Login



Strangely, in this website and maybe in Drupal in generatl, the Create new account functionality is hiding behind the Login feature, something that I always thought should be separate from one another because it is a slightly confusing place for such functionality to be lurking.

Next I clicked on Create New Account in the Login screen:



Now the mymanthemaker.com new user registration page looked like this:




REFERENCES:



No comments:

Post a Comment