Building Drupal 8 Website From Scratch - Part 2 (Content Types, Custom Fields, Manage Display)

| Drupal Development | 0 seen

In the second part of the series Building Drupal 8 Website from the scratch I will cover details on working with content types and node displays. Make sure to check out part 1, before proceeding.

When comparing Drupal 7 to Drupal 8, there is little difference regarding managing content types, except most of the cool features we have been used to have in Drupal 7 by using additional modules and fields, are already built in Drupal 8 core. Which is amazing.

In Drupal 8, fields, like taxonomy term and image field are already enabled by default. If you installed Drupal 8, with standard features (not minimal) - by default there should be already two content types defined for you - basic page and article. 

For the ease of this article, I will cover details on how to work with article content type, but the same rules apply for basic page and for any other custom built content type. As usual, for this tutorial, I will use a live example, my latest Drupal niche website  - cloudminingreview.info

There are few things I'm looking to have for articles to be featured in article content types for this website. Obliviously we are talking about the title and body (or content). Image field (for illustrative article headings), category field and tag field is my basic requirements.

The great with Drupal 8, 90% of my desires are already built in the core. Amazing.

Custom display for Article Content type in Drupal 8

Custom display for Article Content type in Drupal 8

This is an example of how I have I display article content type in Drupal 8. An example here: How To Register For HashFlare.io cloud mining contract and start earning

As a matter of fact, I have heavily rewritten original display mode and built this page using both Drupal Views and Content Display options. I will cover details about Drupal Views in some of the future tutorial articles, but for this article let's stick with default display modes.

How to hide author and date information in Drupal 8

One thing I like to have a full control is a date and author information with each article. In the above example, you can see, there is no published date nor the author information. This is the stuff I like to make with Drupal views, but before making a custom Drupal views for Author and published date information, we should hide author and date information from the display.

To achieve this, visit admin/structure/types/manage/article and under Display settings uncheck Display author and date information

Hide author and date information in Drupal 8

Hide author and date information in Drupal 8

Save content type and check how well does it look now.

Adding custom fields to Drupal 8 Content Types

I have written a good amount of info about this regarding Drupal 7, see: Building a Drupal site from scratch - part 13 - working with node display,  but let's refresh our knowledge and see how to add custom fields in Drupal 8.

In Cloud Mining Review website I wanted to add additional category field, and listing each article under a separate category, by default we have already tags enabled in a content type, we could stick with tags only, sure.But I like to have both tags and categories. 

Category names displayed in Drupal 8 using Views

Category names displayed in Drupal 8 using Views

As you can see, there are categories Tutorials, Discounts & Promos. Despite the result is achieved using Drupal views function (which I'll cover in some of the next articles). I had predefined Category field for article content type.

Later we will create beautiful Drupal 8 Custom Taxonomy Term Pages with Views

Now, let's stick with the basic part.

From admin/structure/taxonomy/add add a new Vocabulary (Category, for example), as we are going to have a predefined category, list some of the terms, like Tutorials, Discounts e.t.c. Once you are ready, visit admin/structure/types/manage/article/fields and add a new field - Category 

Manage fields for Drupal 8 Content types

Manage fields for Drupal 8 Content types

Here we are simply adding a new Entity reference field naming it Category to reference Vocabulary we just created (Category)

Referencing taxonomy in Drupal 8

Referencing taxonomy in Drupal 8

Save these settings and now from content creation page, you should see the new custom mapped field added to form display

Mapping custom fields in Drupal 8

Mapping custom fields in Drupal 8

Congratulations, now you know how to create new fields and taxonomies in Drupal 8. Also, you have learned how to work with display settings to show.hide author and date information.