Skip to main content
Image
3-opensenselabs-banner_1.jpg

Add Fields to Custom Block Library in Drupal 8

article publisher

Bikash

Drupal

One of the reasons Drupal is popular is because of its flexibility. It provides some useful and out of the box blocks but there are times when you need to create a custom block. That is easy too. However, adding and managing fields can be a tough task for a newbie. In this article, we will observe how we can do so using custom blocks.

First, create a custom block type.

  • Navigate to Manage> Structure> Block Layout> Custom Block Library
     
  • Now select the Block Types tab above.
     
  • Click on the Add Custom Block Type button and label it suitably and click on Save, in this case, we have named it as "Block as field".
     
  • Navigate to Home> Administration>  Structure>  Block layout>  Custom block library
     
  • Select the Block types tab which should take us to a page as shown below. It will be a list of all available block types.
The block types tab contains all the available block types
The Block types tab contains all the available block types
  • Click on the Manage fields tab, which is on the next line and proceed to Add Field. This would open up a new window where one can select the desired field type from the drop-down menu.
The Manage field tab is used to add fields and change configuration of existing ones
The Manage field tab is used to add fields and change configuration of existing ones
  • Select the field from the drop-down field list and click on Save and Continue. 
adding a new field
Select the required field type from the drop-down list
Select the required field type from the drop-down list
  • The next page presents before us a lot of options such as to make the field required, provide default content, specifying the reference method and a few more.
     
  • The manage form display is used to control the appearance of fields in the block also fields can be disabled if an admin wishes so.
Managing the form display
Managing the form display
  • Lastly, the manage display settings manage the view mode i.e. how the content would appear to the end user. To know more about view mode, be sure to check out our article on Display modes by clicking here <link>. Click on save after performing the required changes.

 

Managing the end user display.
Managing the end user display.

Well, that’s how we can add fields to blocks in Drupal 8. In case of any query, feel free to comment below.

Subscribe

Ready to start your digital transformation journey with us?

Related Blogs

SDC: Integrating Storybook & Single Directory Component

Integrating SDC With Storybook OpenSense Labs

Today, we will talk about about Drupal Single Directory Components or SDC and Storybook. Single Directory Components in Drupal allows you…

RFP: How To Create An RFP For Open Source Solutions?

RFP OpenSense Labs

A good Request for Proposals (RFP) or Call for Proposals (CFP) clearly states the goals and expectations of your project and sets the…

Drupal 7 End Of Life: Top Reasons You Should Migrate To Drupal 10

Drupal 7 End Of Life Cover Image OpenSense Labs

Drupal 10 was released in December 2022 and ever since, the community has been pushing its users to do Drupal 7 to 10 migration. As per…