Articles tagged with code example

Using CacheableMetadata in Drupal

Posted on
The Cache API is a powerful feature of Drupal, but it might be hard to figure out how to use it correctly. Over time I have seen different ways to do it, but I believe there is a method better than others.

How to use Drupal once()

Posted on
Drupal implements its own Javascript API. Most of the time, all code should use behaviors that trigger every time something changes on the page - page loaded, ajax request, and so on. On the other hand, it causes issues with code executing more than one time.

How to create a custom logger channel in Drupal

Posted on
Logging is convenient for storing information about important events in the application. You could use it to find out if any errors occurred, debug issues, and any other important information. In this article, you can find an example of creating and using it in dependency injection.

How to add container around CKEditor table

Posted on
Tables can be hard to make responsible. Bootstrap, for example, needs a special div wrapper, but it's not easy when dealing with CKEditor. Here you can find the filter plugin that created div around table elements.

How to hide taxonomy term paths from public

Posted on
Drupal shows all taxonomy term pages as publicly available and lists all related content. In this article, you will find an event subscriber to deny access by default and hook implementation to enable it for some taxonomy terms.