Render a Drupal 8 View programmatically (Render arrays FTW!)

12th Mar 2018

Extra quick tip for Drupal developers: Adding views to your page content is now incredibly straightforward:

$content['editor_tools']['view'] = [
  '#type' => 'view',
  '#name' => 'editor_tools',
  '#display_id' => 'embed',
  '#arguments' => [

And that's it! $content is my render array which I'll return and let Drupal render. I suspect most of the bits there are self-explanatory, but in case they aren't:

  • '#type' => 'view' is the magic that lets Drupal's rendering system know that this array represents a view to render.
  • '#name' is the machine name of the view you want to render.
  • '#display_id' is the display ID...
Read more

Quickly creating github pull requests from the command line

2nd Mar 2018

Following on from my feature branching bash script I thought I would do another quick post about a super handy tool I use to streamline my dev workflow a little more (marginal gains and all that).

Hub is a command line tool that lets you do all kinds of clever github stuff without ever having to open a browser.  

All the setup instructions are here - it's pretty simple to get working (if I can do it ...).  I wasn't quite brave enough to alias my git command so I skipped that bit!

Read more

A quick bash script to make feature branching a bit easier

8th Feb 2018

During a typical working day I can easily flip between 15 projects, fixing small bugs or working on various features.  Each flip normally requires a new feature branch, and i found myself repeating myself.  A lot.  I'm a parent so I'm pretty used to this, but in this instance I figured I could probably do something about it - so put together a simple bash script.

Read more

Avoiding sending Personally Identifiable Information (PII) to Google Analytics with Drupal

1st Feb 2018

Having PII in Google Analytics is a big no no, it violates their terms of service and can cause you to have to remove all your analytics data - not fun.

The good news is, most 'standard' Drupal sites using most 'standard' GA implementations avoid sending any PII with one exception - and that is the user password reset page.  

The problem occurs when a user attempts to login but enters and incorrect password.  They are then presented with a message saying "Unrecognised username or password.  Have you forgotten your password?".  The "forgotten your password" bit is a link to...

Read more