Extra Block Types (EBT) - New Layout Builder experience❗
Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.
❗Extra Paragraph Types (EPT) - New Paragraphs experience
Extra Paragraph Types (EPT) - analogical paragraph based set of modules.
- Home
- Drupal Documentation
- Creating modules for Drupal
- Creating Field Types, Widgets, and Formatters in Drupal
Field Types, Widgets and Formatters are plugins
Menu
- Understanding Drupal
- Drupal System Requirements
- Installing Drupal 8
- Drupal 8 Update
- Drupal Site Administration
- Drupal 8 Modules
- Drupal Modules Comparison
- Drupal Themes
- Drupal field types
- Configuration Management
- Multisite Drupal
- Accessibility Features
- Troubleshooting in Drupal
-
Creating modules for Drupal
- Getting started - Drupal technical documentation
- Create Drupal module outline
- Naming and placing your Drupal module
- Mention Drupal about your module using .info.yml file
- Add composer.json file
- Output "Hello World" on page using Drupal module
- Adding main controller
- Add routing file
- Add a menu link
- Go next
- Add configuration for default values
- Enable default configuration in your Drupal 8 module
- Practical Guide to Creating Basic Modules in Drupal 8
- Drupal module structure
- Drupal configuration form
- Defining and Using Your Own Configuration in Drupal
- Create page in Drupal programmatically
- Creating block in Drupal module programmatically
- Creating Field Types, Widgets, and Formatters in Drupal
- Event Subscriber and Event Dispatcher. Working with events in Drupal
- Creating image style for Views in Drupal
- Adding template in Drupal module for theming
- Add CSS and JavaScript in Drupal module
- Testing Drupal module
- Publish your module on drupal.org
- Understanding hooks
- Drupal 8 API
- Theming in Drupal
- Upgrade to Drupal 11
In Drupal 8, all field types, widgets, and formatters are plugins.
They are automatically discovered if placed in the expected directory structure and use the correct annotation.
The directory structure for a module that implements all three looks like this:
foo_bar_fields
- foo_bar_fields.info.yml
- src/
- Plugin/
- Field/
- FieldType/
- FooItem.php
- FieldFormatter/
- FooBarFormatter.php
- FieldWidget/
- FooBarWidget.php
- FieldType/
- Field/
- Plugin/
In this tutorial, we will create a custom field type, field formatter, and field widget that generates a random string and displays it.
The module will be named random and will follow this structure:
random
- random.info.yml
- src/
- Plugin/
- Field/
- FieldType/
- RandomItem.php
- FieldFormatter/
- RandomDefaultFormatter.php
- FieldWidget/
- RandomDefaultWidget.php
- FieldType/
- Field/
- Plugin/