Articles about Drupal

Drupal - My view has a null module dependency

We often get asked to troubleshoot issues on Drupal sites and recently, twice in succession on different Drupal 8 sites, we came across an issue where a configuration file contained the word null in its list of module dependencies. This was causing a number of issues and is clearly wrong. In this post we investigate the issue and show how it can be overcome.

BOM disposal

Occassionally when you get files from someone else or use a new text editor you encounter an issue with hidden characters or incorrect encoding that can be a pain to track down.

A common one of these that I haven't encountered for ages, (since we moved from Windows to OSX for development) is the Byte Order Mark (BOM).

This is a simple marker that indicates the encoding order of UTF-8 files and should in itself be no problem. It does however cause an issue when the file is included within other files (by PHP as *.inc files for example) such as in template files.

Stock for Drupal 8 commerce - Technical overview & use cases

The business requirements

Drawing on the experience of maintaining the Drupal 7 stock module and working with a number of ERPs over the years we have come up with a completely new architecture for Drupal 8 commerce stock module.

The following are the 4 main challenges that I encountered with the Drupal 7 module that needed addressing:

Drupal 8 Release

On the 19th November 2015 a new version of the Drupal content management system (CMS) will be released - Drupal 8.

This new version has been over four years in development and has seen contributions from over three thousand people. It contains well over 200 new features, uses object orientated code and is probably the most significant release to date.

Drupal Commerce site for Moscow bakery

We were commissioned to create a Drupal Commerce based web site for a top Moscow bakery.
The site is a custom themed multilingual site offering online ordering, delivery slot choice alongside recipes and other product information.
The Drupal Commerce framework is an ideal platform for the creation of an online shop and with a degree of customisation provides an excellent base for this multilingual online bakery.

Apache: Better blocking with common rules

This is a follow on post to the 'Using Apache to block Spammers' post.
It shows how to use Includes in your Apache configuration to re-use useful rules.

A web site to support the Reforestation of the Atlantic Forest

The Royal Botanical Gardens at Kew engaged us to convert an existing MS Access desktop database into a multilingual CMS based web site. The site is a responsive mobile and tablet friendly CMS based web site that enables the management of a database of tree data for conservation purposes. The data relate to trees native to the Atlantic Forests of Brazil that could be used for reforestation - The South Eastern Bahia Atlantic forest database.

Working with Drupal commerce order total

The following gists shows a few approaches for working with Drupal commerce order totals.
All three examples retrieve the order total as two components Ex Vat and VAT:

The first example shows how to get nicely formatted amounts. This is easily done using two functions:
commerce_price_component_total() - Returns the total value and currency for the specified price component in a price array.
commerce_currency_format() - formats the amount with the correct localization and currency symbol

Dickies Workwear - Online Catalogue responsive web site

The internationally renowned manufacture of hard wearing and fashionable workwear - Dickies - engaged us to create a web site for their workwear range.
The web site presents their range of workwear and links through to a network of online distributors and retail shops. The site is presented in 10 languages, is responsive and optimised for multilingual SEO.
The site also provides access to corporate information and enables the ordering of custom workwear, embroidery and access to the extensive image library of Dickies products.

Drupal Commerce Localisation - translate the currency symbol

I didn't see this one coming but on a Multilingual Russian site we recently built, the client asked us to translate the Russian Rubble symbol "руб" to "RUB" when viewing products in English.

As there are no localized options for currency settings I had a look around the commerce code and came across commerce_currency_format() in commerce.module.

Drupal Form API - Reset Button

I have come across a lot of discussions about how to add a reset button to a form in Drupal 7. Also it would be nice if when we added a reset button it didn't get a class of 'form-submit'. To get around this, rather than using standard method of adding a button to the render array of the form, most solutions opt for using #markup.

Excluding common requests from your apache logs

Log files can get filled up with repeated calls to files such as favicon, robots.txt, images, css js etc
This can be a pain when you need to scan the logs for issues and they are full of unimportant requests.
This is especially so if you use Ultimate Cron in Drupal and run cron every minute - the logs get swamped with the cron calls.
Mostly you want to log the initial request for a page and not all of the resources subsequently requested.
Troubleshooting other issues may mean you would log files such as favicon, images etc - but generally they needlessly fill up your logs.

Apache rewrites to control access to PHP files

There are certain PHP files that you want access to but don't want to make public.
Common examples of these are:

  • PHPInfo.php
  • APC.php
  • memcache.php

You also don't really want to deploy these on all of your sites on a server nor have them in your git repositories for sites.

A neat way of dealing with this is to use rewriting in your web server config files (e.g. Apache, NGINX, IIS etc) to do the following:

Drupal Commerce - Best selling products

Having created a Drupal Commerce site it is likely you may need to have a mechanism to list the best sellers / a count of orders by product or similar.
Her's a quick solution that will help you.
Even if you are familiar with the structure of the commerce model this is still a complex task; linking line items, orders, products, product displays etc.

There is some background discussion here: https://drupal.org/node/1292104

Localizing a Drupal 7 Commerce site a step by step guide

This is going to be a step by step guide for localizing & translating a Drupal 7 commerce site. there are many ways and tools Drupal and its contributed modules support and this is just one of them. 

I will not go into too much explanations but will try and make sure I cover all the steps needed to translate a Drupal commerce site.

Note: commerce kickstart 2 comes with some of this but last time I checked it did not provide full localization and translations features.

Setting translators on a multilingual drupal 7 site

Drupal 7 has great support for multilingual site and has various approaches to content translation and localization.
In this quick recipe post I will cover the setting up of a "Translator" role for the following translation approaches

  • Interface translation: The translation of strings used throughout the site
  • Entity translation: The translation of Nodes and other entities using entity/field translation

I will try and cover other translation & localization approaches at a later stage

Move your body (from views to Display suite)

Lately I find myself more and more moving from views fields to using Display suite layouts. However one bit of functionality I love about views is its text trimming and striping.
What I like to do is create a display suite code field that lets you do this using the original views function. I also try and keep my code in a unit and call it from the display suite (so its not hiding in the DB).

Binary logs are filling up my Mac - Help!

A colleague of mine was running out of disc space on his development machine and on inspecting the disk space usage (use - www.derlien.com) found that MySQL was using up the bulk of the disk.

Collaborative content editing on a Drupal 7 site

Most Drupal sites require more then one person to be able to edit content on the site.
While out of the box Drupal does not support a great collaborative experience, you can easily enable this functionality using a few contrib modules and configuration.

Drupal 7 - How to get information about node types

Each node has a number of properties like name & description.
Drupal 7 core (node.module) provides two useful functions for accessing this data:
node_type_get_names() and node_type_get_types both functions return an array index by the node type.

Contact