Drupal 8 – Customizing Content Types

dr

At this point we could create a new content item using our Event content type. However, the Event content type only has two fields, an Event Title and a Body. Our requirements call for an event description, start date, end date, venue/address, type of seating, assistance available at the venue, type of event and the ability to provide a file that can be downloaded by the site visitor (e.g., a program). Drupal automatically creates a Body field, which we will use for the event description.

The next step is to add the Start Date field. Click the “Add field” button. The next step is to select what type of field to add or alternatively what existing field to add to this content type. A previously created field may reside in another content type and instead of recreating that field, we can reuse the definition by selecting that field from the list of existing fields. A lot of drupal developers use custom content types fields.

After clicking Date, you will see a new field on the screen where you will enter the label for the new field. This label is displayed on the content editing form so the author knows which field they are entering a value for, and is displayed to the end user when the content item is rendered on the site. Since we’re creating the start date for the event, enter “Start Date” into the Label field and click the “Save and continue” button.

The next step in the field creation process is to set the format for our date field, either date and time or just the date, and the number of allowed values. Since events typically have a time associated with them, we’ll leave the value set to “Date and time” for the “Date type” select list. We’ll also leave the “Allowed number of values” option set to “Limited” and “1” because our events only occur once.

You will see the “Allowed number of values” configuration option on every field that you create. You may have situations where you want the author to have the ability to create multiple values for this field. For example, you might have the same event occurring several times in the future. By setting the “Allowed number of values” higher than 1, the content editing form will display the same number of entry fields as you select in the “Allowed number of values” select list. If you change Limited to Unlimited, the author can create as many values as they need to, with an “Add another” button appearing below the field to enable the author to create a new entry. Think about how the field will be used and then set the “Allowed number of values” option. There may be cases where 1 is not the best solution. For this example, however, we’ll leave the value as 1. Click the “Save field settings” button to continue to the next step.

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