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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4 ■ Taxonomy<br />

On the settings page, we have options to change the label we previously created, enter help text that<br />

will be displayed on the content editing form beneath this field, set this field to Required (meaning the<br />

author must select a value from the list before saving the article), and set a default value should the author<br />

not select a value from the list. For the purposes of this demonstration, we’ll leave the Label as previously<br />

set; enter a brief sentence instructing the author to select a value from the list if appropriate for this article;<br />

leave the check box for the Required field unchecked so that it’s optional whether an author selects a type of<br />

sport for any given article; and leave the default value for “Type of sport” set to None. In the reference type<br />

leave the Reference method set to Default. The other option utilizes Views to customize the list of available<br />

values, I’ll talk about Views in Chapter 10. In the list of Vocabularies select Type of Sport by clicking on the<br />

checkbox. This instructs <strong>Drupal</strong> to only display items from the Type of Sport vocabulary when presenting<br />

values to select from to the author. To complete the addition of the new field, click the “Save settings” button,<br />

which will return you to the main admin page for the “Article” content type. By default taxonomy terms are<br />

autocomplete fields, meaning that an author simply types a portion of the term they wish to add and <strong>Drupal</strong><br />

looks to see if a term matching that pattern exists. Autocomplete works well when the taxonomy terms are<br />

known by the author, but in this case we want to present a list of terms for the author to select from. To<br />

change the Type of sport field widget from autocomplete to a select list click on the Manage form display<br />

tab at the to of the list of fields and change the value for List of sports from autocomplete to select list. After<br />

changing the value click the Save button. Authors can now select from the list of terms in the “Type of sport”<br />

vocabulary when authoring an article.<br />

Selecting a Taxonomy Term when Creating Content<br />

Based on our actions in the previous section, creating a new content item using the “Article” content type<br />

will now present the author with a list of values that they can select from to categorize the content they are<br />

authoring. To test this feature, click any of the “create content” links described previously. From the list of<br />

content types listed, click the “Article” content type. When the Create Article page is displayed, notice that<br />

there is a new “Type of sport” select list field where the author can select the type of sport to assign to this<br />

content item (see Figure 4-8). Create a new Article by entering a title, body text, and selecting a type of sport<br />

from the select list.<br />

Figure 4-8. Creating an article<br />

41

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

Saved successfully!

Ooh no, something went wrong!