Get a term's parent TID

Provided we have the TID of the child term, the parent is found by:

Programmatically creating a custom block

Drupal 8. Provided our module is called customblock add the file CustomblockBlock.php to src/Plugin/Block. Inside it put something along the lines of:

Loop through mulitiple field items in Twig

This iterates through the field items but not the field meta data.

Add class name to body class

In the case below we add the is-node as well as the node ID to the body class.

Overriding a service in Drupal 8

Suppose we want to override the maintenance_mode service. This service is responsible for granting and denying permission to users while the website is in maintenance mode. 

Creating a custom service

A simple Drupal 8 example service converting a string to uppercase.

Customizing a user object

// Load the currently logged in user $user = \Drupal\user\Entity\User::...


Subscribe to RSS - Drupal