Drupal

Blog

Drupal 8 messenger api: how to set message examples

Drupal set message was deprecated in Drupal 8.5 and will be removed before Drupal 9. Time for a roundup of this new API and how to use it.

Blog

Get list of active languages in drupal 8

Short snippet to get the enabled languages programmatically

Blog

Add a block class programmically in drupal 8

Small snippet to show how to add a class to your block

Blog

How to add javascript to custom form in drupal 8

The way of handling javascript and css is different from drupal 7. This snippet shows how to do it.

Blog

Allow adding roles but disallow administrator role on the user registration form [drupal 8]

When you give users the permission to administer users, there is a security implication in that users with this permission can add the role 'administrator' role to any user.

Blog

Control block access programmatically in drupal 8

<p>Block access is a powerful way to show or hide content in some contexts. Instead of using contrib modules, this is very easy in small pieces of custom code. The following code prevents access to a block based on a subscription field in the user object.</p>

Blog

How to create a settings form to edit and save custom configuration in drupal 8

<p>The following code shows how to create a custom form in the drupal back-end and how to save custom config defined in your custom module. Powerful stuff and very flexible.</p>

<p>You can update custom config with a settings form you build. <br />
In a custom module *custom_mailing* add a file called *custom_mailing.routing.yml* add the following route:</p>

Blog

Show the file description in a custom formatter in drupal 8

Custom formatters are great to get precise control over your field output. But I ran into something difficult when trying to output the description of a file field.

Blog

Make a views exposed form field required programmatically [drupal 8]

This is an interesting trick to make fields required in the front-end.

Blog

Check in twig if image field has value [drupal 8]

In a node teaser or full view mode it is for front-end purposes needed to know if an image is available. This snippet takes care of it.

Subscribe to Drupal