Using the Content Type to manage content consistently
Blog

Using the Content Type to manage content consistently

In previous blog post we have installed Drupal 8 on our system manually as well as using Drush. Drupal 8 Provides two built in content type Article and Basic page. We can use this to create pages. But most of time we need to either add fields to these content types or we just need to add new content type to organize the content better.

Probably the first change site builders will notice in Drupal 8 are the changes to content types and fields. The field changes affect not only content types, but any entity that can have fields e.g. taxonomy or user profile.

When we edit any content type, there are  some differences in the tabs compared to Drupal 7. No more comment fields and display tab. And now we have a new tab: "Manage form display."

Drupal 7 Article “edit” page

Druapl 7 article edit page

Drupal 8 Article “edit” page

Druapl 8 article edit page

 

In this article i’ll explain followings -

New fields / Adding a new field
Managing fields
Form modes in Drupal 8
Comment form configuration

New fields in Drupal 8

Let's add following five new Fields available in Article content type.

Date, E-mail, Reference, Link & Telephone

We will add these fields step by step.

Step 1.1:  Select “Date” in Add a new field. Let's add the Label as “published Date”.

Druapl 8 adding new field

Step 1.2: Add some value to Allowing no. of values under field settings tabs for limited or unlimited option. Click on Save field settings.

Drupal 8 field setting

Step 1.3: Add the help text and Default value if require. You can select either Current date or  Relative date and hit Save settings

Drupal 8 field configuration page

Now “date” field is available  under Manage Fields on Article

Drupal 8 new filed listing in Content type

Managing fields in Drupal 8

Manage fields only controls how data is structured, where we can configure each fields for our content type.
But under managed field we have an option to hide a specific field, change the widget type, perform inline field setting and save the configuration. In Drupal 8 these two actions are separate.

Drupal 8 manage form Display

Fields which had “Hidden” property would come under Disabled section.

Drupal 8 field Disabled

If we click on gear icon for any of the field item, it will open the field setting section.

Drupal 8 inline form setting

Form modes in Drupal 8:

Drupal 8 has form nodes. so if we go to structure then display mode and select form modes, we can add new form mode. For our content type we can add a new one “generic form mode” and save it.

Drupal 8 form Display

Step 3.1: Once we click on form modes we will be redirecting to entity type. As we have assigned form modes to content type, we will selecting Content

Drupal 8 choose entity type

 

Step 3.2: Now we will go back to our content types and click Manage form display.
scrolling down to bottom of the page, you will find “CUSTOM DISPLAY SETTINGS” as collapsed fieldset. Here we can select our new display form mode “generic custom mode” and save it.

 

Drupal 8 custom form Display

Step 3.3: After saving configuration you will get the drupal message with “configuration” form link on top. If you click on that, drupal will redirect to our new form Display mode “generic custom mode

 

Drupal 8 generic custom mode

This can be used for various real world use cases.  One  use case could be , people of different roles to be able to edit different fields.  we can create a form that includes the different fields for  each user roles.

Drupal 8 generic custom mode page

Comment form configuration:

In Drupal 7 we have  option to  add fields to comments on specific content types. But there was no option to add comments to entities such as users, taxonomy terms.

In Drupal 8 we can configure Comment forms independent of a specific content type. This means we can have a one comment form type for articles and another for other entity type.This also means we can reuse a comment form settings and ensure consistency across your site. Comments are added in the same way like any other fields and there is no a separate configuration tab for “Comment fields” and “Comment display”.

if you don’t want to add a Comment field to a content type, you can’t just override that per-item.

Drupal 8 adding comment as field

 

The comment form settings include:

Default value: Open, Closed, Hidden.
Comment form settings: Threads, Comments per page, Allow title, Show reply, Preview settings.

Drupal 8 comment form settings

Just now we saw, that the comment form settings are similar to the settings for any other field.

Drupal 8 provides Sitebuilders to do more out of the box. There are many excellent enhancements you'll want to know more about. You won't have to learn any crazy new concepts. The UI in Drupal 8 for managing content types and fields has been imporved a lot with great feature.