How to Create a Custom Block in Drupal 9

Posted on: Fri, 09/10/2021 - 19:17 By: Arun AK

Blocks are building blocks of Drupal website. Each content in a Drupal website belongs to one block or other. Blocks can be easily displayed in different part of the webpage using regions in themes.

There are two types of custom blocks in Drupal:

  1. Create using Drupal Graphical User Interface(GUI) system through /admin/structure/block/block-content
  2. Programmatically create based on your requirement

Let's see each method in more detail below.

Unable to determine class for field Drupal 8

Posted on: Fri, 05/01/2020 - 14:08 By: Arun AK

Drupal is a popular and best content management system. Even it is more powerful, and sometimes we have to deal with a tough time if we are not maintaining it well.

Here we see one of the issues that can happen in Drupal 8 if we do not correctly uninstall module before it removes from the file system. Your site might be working correctly on the production server, and the issues can arise after you move your site into a new server or after setup your local dev environment.

Replace template using custom module in Drupal 8

Posted on: Tue, 11/05/2019 - 21:19 By: Arun AK

Sometimes you may need to alter a template that is provided by a module. Usually, you will be able to override the template by copy it into your themes template directory.

But in a case such as Drupal multi-site setup with a single code base and shared the theme, it is difficult to alter template specifically for a particular website. Then if you are doing it using a module you will be able to achieve for a particular website.

The hook hook_theme_registry_alter() will help to alter the template path for a particular theme function.

Programatically show page not found exception in Drupal 8

Posted on: Sun, 01/07/2018 - 08:15 By: Arun AK

During development it is important to make sure not exploiting any kind of security issues. Here we are going to see how can secure server details without showing to public users while handling an exception.

In this example we have a custom menu callback which will process the argument which we are passing with the url. We will pass media id(mid) with the url and it will force prompt download corresponding the media file.

Define custom menu callback: custom_module.routing.yml

Managing with File fields in views - Drupal 8

Posted on: Sun, 06/18/2017 - 16:05 By: Arun AK

In Drupal 8 theming and templating are quite different than in Drupal 7. But D8 is providing very seamless options and lots of addons to make theming easy.

One of the power tool which helps to debugging and theming is Kint. Kint is a powerful and modern PHP debugging tool. Kint wisely detects what kind of data is being displayed and provides nicely formated data.

Subscribe to