Web Developer's Blog

Preparing for Drupal 8, Changes, Controversy and Backdrop

The much anticipated new version of Drupal is due to be released in early 2014, and it’s already causing some controversy amongst current users.

Responsive Performance in Drupal 7

One of the issues we face in responsive theming is on-browser performance across multiple devices. Responsive themes are inherently more taxing on rendering engines, but once we add to the page all the interactive bells and whistles (ex: sliding banners, videos, flying objects) we might be setting the browser up for a serious impact on rendering.

John Hannah at Friendly Machine wrote an in-depth look at this issue, and offers some solid advice in the field of responsive performance:

Adding Javascript to Drupal

Using PHP

The function drupal_add_js() lets you add a reference to a file, as well as inline javascript code:

drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline');

See the function reference page for additional examples and settings.

Mobile Website Testing on Windows 7

The following are a few of the tools I use for testing mobile sites on Windows 7, prior to testing on actual devices:

Opera Mobile Emulator

Emulates the behavior of the Opera browser under multiple devices such as various HTC, LG, Motorola, Nokia, Samsung, Sony Tablet, Amazon Kindle, and a few others. This is my testing tool of choice because it is easy to use, fast and a close representation of the mobile experience.

The Skill Set of a Well-rounded Drupal Web Developer

The design, development and release of a complex website involve a large array of skills that few individuals can master all-together. In actuality, most successful web development efforts rely on a team of specialized individuals to cover the entire skill base.

Most people are in tune to the need for skill diversity. For instance, many people accept that the visual design of a website is often an artistic task performed by a graphic designer, while the configuration of a website is a technical process often performed by a code programmer.

Drupal FAPI: Disabling Form Elements

Access Control of Form Element

We can use the #access directive of the form element so that a permission can be specified using user_access(). For instance:

$form['menu'] = array(
'#type' => 'fieldset',
'#title' => t('My Menu'),
'#access' => user_access('administer menu'),
'#collapsible' => TRUE,
'#collapsed' => !$link['link_title'],

In this case, only users with the “administer menu” permission will see this field rendered.

Drupal Override: Understanding Themable Output

Drupal Theming is hard enough when it comes to dealing with CSS & browser rendering issues. On the other end, for programmers the code templating process can be powerful and convenient once we get the hang of Drupal’s theming system.

A community documentation page at Drupal.org offers a good introductory overview of themable output, covering the basics of data source and overrides:

Drupal Search: Disable Indexing of a Node Taxonomy

The following code stops Drupal 6 from indexing a node’s taxonomy as part of its content. The code uses hook_nodeapi to alter the node object when it is being built to update the index. At this stage it is possible to add, remove or alter any of the node’s elements.

Drupal: Generate your own view with PHP

This example shows how to generate a list of nodes using the Drupal framework. The code assumes you have already loaded Drupal (see Bootstrap if you want to place this code in an external script.)

1. Query the database for node ids
2. Load the full nodes based on their ids
3. Generate html output

Drupal_bootstrap: Connect to Drupal from an External PHP Script

For testing purposes, or for executing Drupal-related operations but from a PHP script that runs outside of Drupal, I often create independent PHP files that are not meant to be Drupal modules but still require access to Drupal’s database, functions and modules.

Using the function drupal_bootstrap, located within includes/bootstrap.inc, your script can load Drupal and make all of Drupal’s functionality accessible to your script.