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.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

Articles

13/04/2025, by Ivan

Add the following method to the HelloBlock class. In this example, it's located in the src/Plugin/Block/HelloBlock.php file, but as you start thinking in a more OOP-oriented way, where it's physically located in the file structure is less important than the namespace. If you're a savvy OO programmer, you'll keep both closely aligned. But just in case, the namespace—very similar to the module's folder name and machine name from our earlier discussion—will be important later when you want to interact with your module’s code programmatically.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

To use block instance configuration, we can modify the build() method of the HelloBlock class:

/**
 * {@inheritdoc}
 */  
public function build() {
  $config = $this->getConfiguration();

  if (!empty($config['hello_block_name'])) {
    $name = $config['hello_block_name'];
  }
  else {
    $name = $this->t('to no one');
  }

  return [
    '#markup' => $this->t('Hello @name!', [
      '@name' => $name,
    ]),
  ];
}

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

Part V of the Practical Guide to Creating Basic Drupal 8 Modules
From .info to tests, just the basics

Remember at the beginning of this tutorial I mentioned we’d define a block with a form? Well, now is the time to dive into it.

Source URL:

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

This guide includes tutorials on how to create a custom field type, widget, and formatter in Drupal 8.

Source authors:

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

This tutorial was originally published on Web Wash. However, Berdir asked if I could post the tutorial here, so here it is.

The module in Drupal 7 allows you to store code examples/snippets in a field. It comes with a custom field called "Snippets field" and displays three form elements: description, source code, and syntax highlighting mode (which programming language).

But now it's time to update the module to Drupal 8.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

Field types define the properties and behavior of fields. Field types are defined as plugins, so it is recommended to review the Plugin API before creating a new field type.

To create a field type in Drupal 8, you need a class with a @FieldType annotation.

Location of the field type class should be placed in MODULE_NAME/src/Plugin/Field/FieldType
Example: /modules/foo/src/Plugin/Field/FieldType/BazItem.php

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

Field widgets are used to visualize a field within forms. Field widgets are defined as plugins, so it is recommended to review the Plugin API before writing a new field type.

To create a field widget in Drupal 8, you need a class with the @FieldWidget annotation.

Location of the field widget class should be /[MODULE_NAME]/src/Plugin/Field/FieldWidget. For example, /foo/src/Plugin/Field/FieldWidget/BarWidget.php.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

The field formatter module formats field data for viewing by the end user. Field formatters are defined as plugins, so it's recommended to review the Plugin API before writing a new field formatter.

Field Formatter Class

File: /modules/random/src/Plugin/Field/FieldFormatter/RandomDefaultFormatter.php

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

Overview of Event Systems

Event systems are used in many complex applications as a way to allow extensions to alter the behavior of the system. An event system can be implemented in various ways, but the concepts and components that make up the system are generally the same.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

13/04/2025, by Ivan

Creating a Views display style plugin may seem like a daunting task, but it's easier than it looks. Here's a step-by-step guide on how to do it, complete with source code.

You can download the ready-made code here: TARDIS (although it's still in dev). And if you need an introduction to Drupal 8 modules, here's a practical guide to creating basic Drupal 8 modules.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.