I had to update a Drupal 7 site recently and needed to change the field keys of a list field to be different values. This wasn't possible from within Drupal as it does a pre-check to make sure that the key doesn't already exist. If it finds any values present in the database with that key then it will reject the change. This is absolutely correct but causes a little bit of an issue when you need to update these values.
The 9th PHPNW was held on the 1st and 2nd of October 2016 and I was in attendance with around 400 people. The venue was the Manchester Conference Centre, which is where the event has been for the past few years. It's a nice place with helpful and friendly staff, lots of rooms, great food and even a good bar. After a quick introduction from the organizers Jeremy Coates and Rick Ogden) and a session from the platinum sponsors UKFast we started the conference proper.
The European DrupalCon was held in Dublin from 26th - 30th September and I went along with a couple of colleagues to learn a few things about Drupal. I have been back from the conference for a few days now, and I wanted to write down some of the highlights of the conference in a blog post. There is a lot going on at DrupalCon and with 2000+ people, 3 full days of sessions, 2 tutorial days, multiple parties and over 10,000 cups of coffee consumed there is too much to write about here.
I was recently asked to implement a feature on a Drupal site where all nodes of a certain type would redirect to a main listing page if that node had been unpublished. The problem in doing this is that if a post is unpublished then Drupal will issue an access denied response quite early on in the boot process. When the menu item is loaded it goes through an access callback which sees that the post is unpublished and issues an access denied before anything else can happen. So in this situation you can't use things like Rules to redirect users as the rule is never triggered.
To find out if the current user is anonymous use the following.
This can be used as part of an if statement like this:
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();