Creating twig views template suggestions for a custom entity

I had this views field in a view that renders custom entities. Unfortunately, the suggestions do not come out of the box. Here is how to add them.

Comparing two dates in drupal the correct way

Comparing dates is a common action when programming. But you could have side effects mixing UTC and timezones... This snippet shows you how to do it the correct way.

Render a view with contextual filters programmatically in Drupal 9

A snippet of how to render a view inside a controller.

How to use HTML markup in hook_mail in drupal 9

I found a problem while sending confirmation e-mails. My HTML was escaped in translation strings. This fixed it.

How to check if a node entity is a newly save one

When working with entity forms I discovered this interesting piece detecting whether an entity is a newly saved one.

Directly get title of a referenced entity in Drupal 8 or 9

Entity references are common practice in drupal. With this snippet you can directly get the title of a referenced entity.

How to set default value of a drupal node form or entity form

Lately I had to prefill values on an entity form. Somewhat it did not work directly. Here is a working snippet.

How to set default value for entity reference programmatically in a form in drupal

Prefilling values is a common task. This snippet shows how to prefill a entity reference field

How to throw an exception to users in drupal

With custom development come a lot of entry points for users. This snippet throws access denied for users that are too curious on some paths.

Subscribe to Drupal