Drupal 9.x

How to create pager in drupal 8/9 for custom data set

Sometimes we need to create a pager for custom data sets, such as retrieving specific types of nodes and applying a filter on top of it to get the expected data set.

In this post, I am going to create a custom Drupal module named pager_example, which will create a pager for a custom data set.

Register a path where we will display a page with a pager using a custom data set. For that, I am going to create a routing file with the name "pager_example.routing.yml", which will have the following snippet:

0/5

Use of Drupal module uninstall validators and lazy services

Sometimes we do not want users to uninstall a Drupal module directly, but instead want to perform some checks first.

Let's take a scenario where installing a custom module creates node types along with some fields. Later on If a user wishes to uninstall that module (assuming some content has already been created on the site using the node types that are created by this module), then uninstalling that module can cause a serious problem. It should ask the user to delete the content first that has been created on the site using these node types before uninstalling the module.

0/5

Setup Drupal 9 with acquia BLT

First we will create a Drupal 9 project with the recommended template using the below command.

composer create-project drupal/recommended-project blt-drupal --no-install

This will create a project with the name blt-drupal, since Acquia BLT requires a document root to be docroot, so let's update the project's composer.json file accordingly.

0/5

Setup PHPUnit for Drupal 8/9

PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit architecture for unit testing frameworks that originated with SUnit and became popular with JUnit. PHPUnit was created by Sebastian Bergmann and its development is hosted on GitHub.

In this example, we are going to setup PHP Unit for Drupal 8/9 projects, so let's create a vanilla Drupal project with the recommended template.

  • Create a Drupal project with composer using the recommended template.

0/5