18.11.2015 Views

Beginning Drupal 8

Todd Tomlinson - Beginning Drupal 8 (The Expert's Voice in Drupal) - 2015

Todd Tomlinson - Beginning Drupal 8 (The Expert's Voice in Drupal) - 2015

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Other Field Types<br />

Chapter 5 ■ Content Types<br />

In our Event content type, we created a set of fields for authors to enter values for date and venue. There may<br />

be instances where a text field is less effective than using one of the following field types:<br />

• Radio buttons: Great for providing a list of options to the author and only allowing<br />

the selection of a single item from the list.<br />

• Check boxes: Perfect for providing a list of options to the author, allowing selection of<br />

one or more items in the list.<br />

• Select list: Great for long a list of items to select from; for example, all of the countries<br />

in the world.<br />

• File upload: The right field to use when you want to provide the ability to upload and<br />

attach a file to a piece of content.<br />

• Image upload: The field type to use when you want to upload and display an image.<br />

• Text area: The field to use when the author is expected to enter paragraphs of<br />

content. It provides a box with multiple lines, whereas a text field has only a single<br />

line of text.<br />

• Numeric field: Perfect when you want the author to enter numbers only.<br />

• Entity reference fields: It’s the field to use when you want to associate and display<br />

another content item with the item that you are creating. An example could be<br />

that your site has a content type called Biography that contains a headshot and<br />

biographical information about performing artists. If you wanted to include an<br />

artist’s headshot and biography on an Event content item you could use the entity<br />

reference field to link the event to the artist’s Biography, displaying the headshot and<br />

biography from the existing content item instead of having to manually re-enter the<br />

biographical information the Event.<br />

• Term reference field: When you want to include taxonomy terms as part of your<br />

content item, this is the field to use.<br />

The field types listed here are part of <strong>Drupal</strong> 8 core. There are other custom field types that are available<br />

as contributed modules. For a list of those modules, please visit www.drupal.org/project/modules, choose<br />

the Fields item in the “Module categories” filter, and click Search. You’ll find a list of add-on modules that<br />

provide value-added capabilities, like other field types. You can install additional modules by following the<br />

process described in Chapter 12.<br />

It is likely that you will come across the need to use one of the other field types as you create new content<br />

types. We will expand on our Event content type by adding several additional fields using other types of fields.<br />

Radio Buttons<br />

Radio buttons are useful when you want to present the author with a list of values from which they can<br />

select only a single item (check boxes are used when you want the author to have the ability to select one<br />

or more values). We will expand our Event content type to include the ability to select the type of seating<br />

that will be available at the event: either reserved seating or general admission. To start the process, click<br />

the Manage link at the top of the page, click Structure in the submenu, followed by the “Content types” link<br />

on the Structure page and the “Manage fields” tab for the Event content type. Click the “Add field” button<br />

to start the process. Figure 5-17 shows the list of field types. Since we are creating a radio button–based list,<br />

select the “List (text)” option. A field for the Label will appear after selecting the List option. Enter “Type of<br />

Seating” in the Label field, and then click the “Save and continue” button.<br />

59

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!