Drupal 8 Fields – Select Lists and File Uploads

drupp

Select lists are often called drop-down lists. To demonstrate select lists, let’s create a new field for the Event content type that lists whether the event is a concert, a play, or a lecture. Creating a select list is similar to creating the previous field types covered. On the “Manage fields” page for the Event content type, click the “Add field” button. Select “List (text)” for the field type (refer to Figure 5-17) and enter “Type of Event” in the Label field. After setting these values, click the “Save and continue” button to proceed with the definition of your new select list field.

On the next screen, as in previous examples, enter a key|label pair for each of the options to be listed. Enter concert|Concert, play|Play, and lecture|Lecture in the “Allowed values list,” with one set of key|label values per line. Leave the “Allowed number of values” set to “Limited” and “1.” To proceed, click the “Save field settings” button. On the next configuration screen, click “Save settings” after you have set any values that you wish to change on the form.

In previous examples, we had to click the “Manage form display” tab and change the widget type from “Select list” to “Check boxes/radio buttons.” Since we want to display a select list, there is no need to change the value. You are now ready to use your new select list field.

The file upload field type presents a file browser button that allows an author to browse their local computer for a file to upload to Drupal and attach to the content item that they are creating. Drupal developers use this filed for different files. Creating a file upload field is nearly identical to the procedure for creating other field types. We will expand our Event content type to include the ability to attach the program for the event. As with previous fields, navigate to the Event content type’s “Manage fields” page and click the “Add field” button. On the “Add field” screen, select “File” as the field type and enter “Event Program” in the Label field. Click “Save and continue” to proceed to the next step.

On the “Field settings” page, check the “Enable Display field” check box and the “Files displayed by default” check box. Checking these boxes provides the author with the option of displaying a link to the file when visitors are viewing that content item. By default, the destination for the uploaded file will be the “Public files” directory, which is a configurable destination defined by the site administrator. Next, in the “Allowed number of values” field, set the number of file uploads that will be enabled for content authors.

We will leave the option set to “Limited” and “1” as we only foresee the need to allow a content author to upload a single event program file per event. Depending on your requirements, you may change the number of allowed file uploads. After setting the values on the form, click the “Save field settings” button.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s