Blog

Drupal 8: Detecting An Anonymous User

Tuesday, June 28, 2016 - 10:38

To find out if the current user is anonymous use the following.

\Drupal::currentUser()->isAnonymous();

This can be used as part of an if statement like this:

Category: 

Drupal 8: Get The Current Language

Tuesday, April 26, 2016 - 16:27

To get the currently selected language on a Drupal 8 site you need to run the following.

$language = \Drupal::languageManager()->getCurrentLanguage()->getId();

This will return the 2 character ISO language code for the language. So for English this would be "en".

To get the language name instead of the language code use this.

$language =  \Drupal::languageManager()->getCurrentLanguage()->getName();
Category: 

Drupal 8: Include A Twig Template

Friday, April 1, 2016 - 16:01

When creating re-usable theme templates in Drupal 8 it's quite easy to include that template by using the following snippet.

{% include directory ~ '/templates/parts/footer.html.twig' %}

This assumes that your footer.html.twig template file is kept in the same theme as the template you are working on. It's also good practice to add the template part to a directory called 'parts' or 'components' to separate them from the normal Drupal templates.

Category: 

DrupalCamp London 2016: A Review

Friday, April 1, 2016 - 15:42

DrupalCamp London, now in it's 4th year, was held of the weekend of the 4th, 5th and 6th of March at The University of London campus in London. Myself and a few other developers from Manchester headed down for the weekend to attend. I wasn't able to attend the CXO day on the 4th, but we were all in attendance for the camp event.

Category: 

Overriding Drupal 7 Theme Functions In Module Files

Wednesday, December 16, 2015 - 11:23

When overriding theme functions in Drupal 7 you would normally copy the theme function into the template.php and alter it to suit your needs. This isn't always convenient though, especially if you are trying to abstract functionality into modules and not have code in your theme layer that is reliant on module code. If you add theme override functions to your module files then they won't do anything as Drupal isn't looking for them there and won't pick them up.

Category: 

Interrogating DNS Records

Monday, November 30, 2015 - 22:29

DNS records, as many of you will already know, are commonly used to translate a human readable address into an IP address. This means that instead of visiting a website by typing in it's IP address you can just type in the easy to remember DNS address. I won't talk too much about how DNS records work here, but if you want to know more then you can read the awesome and easy to understand how DNS works commic.

Category: