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 5<br />

Content Types<br />

If you ask <strong>Drupal</strong> developers what the most powerful feature of <strong>Drupal</strong> is, many will say it’s <strong>Drupal</strong>’s ability<br />

to create custom content types. What is a content type? Think of a content type as a template that you<br />

provide to users who author content on your site. You may decide that the standard content types that come<br />

with <strong>Drupal</strong> out of the box, “Basic page” and “Article,” provide all the features you need for your site. But it’s<br />

likely that you’ll encounter situations where you want more control over how users enter information and<br />

how that information is displayed on your site, and that’s where custom content types come into play. In<br />

this chapter I’ll show you how simple it is to create a new content type from scratch. Hold on to your tickets,<br />

we’re about to take off!<br />

The Basic Page and Article Content Types<br />

When you install <strong>Drupal</strong> 8 you automatically receive two content types that have been defined by the team<br />

who maintains <strong>Drupal</strong> core: the Basic page and Article. If you author a piece of content using the Basic page<br />

content type, you will see that it provides two basic fields: a title and a body.<br />

An author using the Basic page content type simply enters a title (a required field as indicated by the red<br />

asterisk) and the text of their content in the Body field. The Body field is flexible and can contain whatever<br />

the author feels like writing about. The author could<br />

• Write an entire book in the Body field, including HTML markup (headings, tables,<br />

CSS, and so on).<br />

• Insert pictures.<br />

• Write a single sentence.<br />

The Article content type is similar to the Basic page, except it offers the ability to upload a picture as a<br />

stand-alone element, such as a banner image for the article (not embedded in the body text), and define a<br />

set of tags that can be used to categorize the content (see Chapter 4 for details on categorizing content).<br />

Like a Basic page, an Article can be used to author content about any subject, and the body area allows<br />

for entering free-form text.<br />

While the Basic page and Article content types are perfect for general content, there will likely be cases<br />

where you want to provide some form of structure around the information that is captured. You may want to<br />

• Require that certain information is entered before the author submits the content<br />

item for publishing; for example, the start date and time for an event, the address of<br />

the venue where the event is being held, and a link to the event on a Google map.<br />

• Have the ability to perform calculations based on the information that is captured in<br />

a content item.<br />

47

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

Saved successfully!

Ooh no, something went wrong!