Blog

Drupal 8 l() function - creating a link

The Drupal link function or l() function is a handy function you've likely used many times over the years of development. All the way back to Drupal 4.6 (my first version of Drupal) it's been a standard, something I've used so many times I don't even have to think about it. Its ability to correctly handle aliased paths, add an active class and an optional destination, makes it simple to implement yet very useful in just about any Drupal site.

A Drupal Development Environment on Windows

As Drupal developers we're always learning new tricks of the trade, be it modules, hooks, theme functions, or simply a new feature implementation. With all of the information online centered around Drupal code, there is surprisingly little to be found regarding the tools used to develop it. In this post I will break down my personal Drupal development environment, and the various tools I use in day to day development.

A Drupal Workflow for Small Teams

Drupal development workflows come in a wide range, from a solo developer working on a shared web server, to a large team committing changes via Git to a central staging environment. We land somewhere in the middle.

As a tight-knit and efficiency minded development team, we have arrived at an ideal workflow which combines aspects of on-server development with the power and reliability of separate version controlled environments. Our platform of choice is Pantheon, which makes this setup a breeze.

Drupal Form API & Adding Entity Form Fields

It seems my love for Drupal and its Form API is always expanding, yep, kinda creepy sounding but to a web geek such as myself, it's perfectly normal to love a CMS and its API's!

In building my custom form I required an entity field which is present on user creation. Instead of duplicating the field, grabbing the current value and then saving the new value with an user_save() it's best practice to let Drupal handle the heavy lifting, since we don't want to duplicate tried and tested functionality or have to update the custom field should anything change to the entity field.

Rendering Drupal Views in code

Having a query builder like Views at your fingertips is fantastic on so many levels. I'm not going to get into my deep and semi-weird love affair with Views at this point in time, but I will show you how to programmatically display your Views display in code. This can be useful in a custom module, perhaps in a hook_node_view or maybe in one of your node or page templates.

In this example I'll add my View to my blog nodes. I'll just append my View to the bottom of the blog content. We'll want to use the views_embed_view() function to render our desired View display.

Drupal Form API - Using Ajax

I love Drupal's Form API. In just about every project we are either modifying or creating custom forms and thankfully, Drupal's Form API makes executing these tasks a fairly easy process. Everybody loves Ajax so in this tutorial we'll combine these two bits of awesomeness to produce some custom 'ajaxified' forms.

Lets start out with a hook_menu so we have a nice page for our example form. You'll see the "page callback" is the function "drupal_get_form" and our "page argument" is our function that will simply return our associative array.

Embedded Twitter feed in Drupal 7 using the Twitter Pull module

There are many Twitter modules for Drupal out there and I've gone through them all. Twitter pull does the job perfectly. It's not a surprise to anyone how huge social media is nowadays. If you have a website you should have some degree of social media integration, be it a simple link to your Twitter, Facebook or LinkedIn profiles, or a full blown embedded feed of your posts and tweets. A lot of clients these days are requesting embedded Twitter feeds, much like the one we employ in our footer.