FlexSlider in Drupal using Entity Field Query (EFQ)

Today I learnt how to stop using views for every little listing of entities while staying away from hacking SQL queries manually.

I'm a bit ashamed I haven't had a look at the infamous EntityFieldQuery class this far.

Here's my example that builds and inserts a FlexSlider slideshow within my page.tpl.php only for the front page.

In my case FlexSlider is installed and registered as a Library using Libraries and the FlexSlider module (making it possible to load the necessary assets using drupal_add_library

Fixing Undefined index: distribution_name in drupal_install_profile_distribution_name()

After my latest (minor) Drupal update I kept on getting the following error message on the modules page:

Notice: Undefined index: distribution_name in drupal_install_profile_distribution_name() (Zeile 207 von/srv/www/vhosts/badeninfreiburg.de/httpdocs/includes/install.inc).

I've only been using the default installation profile and never changed anything regarding that. This issue might happen after running update.php.

There are many proposed solutions floating around, but the one that did the trick for me was really simple:

To minimize the number of new comments asking for it, here's a work-around for current Drupal 7 users: You need to enable the profile used to install Drupal by updating the system table. For example: UPDATE system SET status=1 WHERE name='standard'; will enable the Standard profile. If you don't know which profile was used, just use 'standard'.

Configure CKEditor to allow enterting empty tags

My previous post was about convincing CKEditor to not stripping class attributes from the markup. But the issues I had went beyond allowing class attributes.

I need the following markup to be rendered exactly as shown:

<p class="btn medium default"><a href="/node/9">Zur Kontaktseite <i class="icon-right-open-big"></i></a></p>

The (empty) <i> tag kept on being removed and it turned out to be more complicated than expected to change that behavior.

Here are the steps to allow empty <i> Tags in CKEditor (4.3.x) inside Drupal (7.x).

Allowing certain attributes on specific HTML elements in CKeditor within Drupal


The CKEditor Drupal Module now has a dedicated configuration for ACF where you can put your Extra allowed content in a text area that is labeled as such!

CKEditor (version 4+) by default does a great job filtering unwanted markup, so it's highly recommended not to disable the Advanced Content Filter (AFC).

You could create your complete own set of rules to define which tags and attributes to allow in your markup using config.allowedContent, but that is ususally not what you'll need if you only want to add a little bit more freedom of tags or attributes you can use within CKEditor. That's where config.extraAllowedContent comes into play: it keeps your default Content Filtering rules and extends them with only the stuff you specify.

In my case I simply needed to allow three class names to be allowed on any <p> tag.

Make a Drupal Field available in the Page Template

Sometimes there's a need to render a Drupal field's value outside the scope of a node template. I used to achieve this with either Display Suite or CCK Blocks. As I'm about to change my workflow towards putting more theming stuff back to code (where it belongs) instead of clicking around slow and clumsy web interfaces I needed another solution.

1. Implement template_preprocess_page() in your theme's template.php

Of course you'll need to replace MYTHEME with the name of your theme, $stage_images with an arbitrary name of your choice and field_stage_images with the name of the field you want to render.

Customizing the Drupal Search Form to make use of Gumby's UI Kit

Yesterday I had a hard time modifying the output of the Search Form of Drupal 7. I needed to modify its HTML, adding wrappers, changing the input to a <button> tag, adding classes and additional markup to insert a font based icon into the button. I'm using the awesome Gumbyframework and took code from travisc's sandbox project, which itself seems to be heavily based on the Bootstrap theme for Drupal.

However, I like to start my themes from scratch with minimal overhead, so here's the stuff I extracted from above mentioned projects and changed a bit to make it work with my current setup (using Gumby 2.6.3).

Everything is inside the template.php of my theme (MYTHEME), so change that to your theme name.

This will change the search block form as well as the search form on the search page itself. If you only want it to affect one of those just change the implementation of hook_form_alter() accordingly.

Issues with Moneyscripts File Download Suite

I just had a hard time to set up the paid Drupal module File Download Suite with PayPal as a the payment method. Payments got stuck, emails haven't been sent and user accounts weren't created when they should have been.

Here's what I did to solve the issues and finally making successful purchases:

  • remove any .htaccess password protection on the dev site
  • set up my PayPal (sandbox) account to auto-accept payments in any currency (accept and convert them automatically), you find this option somewhere hidden in your merchant accounts selling preferences
  • don't use the module Automatic User Names as it will throw PDO exceptions when moneyscripts tries to create a new user account for your order

Now there are only some translation issues left to be resolved and everything will hopefully work as planned.

Less RAM for Drupal 7 with PHP 5.5

There seems to be a significant performance gain with Drupal running on PHP 5.5. The average memory usage on memory-hungry Views went down ~50% on a site I switched to PHP's latest version. Seems the newly introduced OPcache works really well. If you're not afraid of some warnings about the usage of (now) deprecated functions - go ahead and try it.

If your hosting company doesn't offer PHP 5.5 it's time to reconsider: give Uberspace a shot, they have 5.5 as default (and they also have an easy way to change to other versions, of course). Actually, even if your host does offer PHP 5.5, you should consider switching ;)

Don't call me Custom

Just a quick one: Save yourself some trouble and don't ever name your Drupal module anything that ends on _custom, it'll save you some headaches. For example getting unexplainable errors like Warning: Illegal offset type in isset or empty in drupal_theme_access () (line 53 in includes / theme.inc) despite being quite sure you did everything right.

This will happen as soon as your module implements hook_theme.

I found this out thanks to Spiderneo blogging (en francais!) about it. Merci beaucoup :)


Loading Drupal SimpleAds' JavaScript with drupal_add_js

I'm working on a site that utilizes the Drupal module SimpleAds. In an effort to optimize front end performance I moved all my theme's Javascript to the Footer (by simply moving <?php print $scripts; ?> around in html.tpl.php). After doing that the ads disappeared and my browsers console telling me Uncaught ReferenceError: _simpelads_load is not defined.

The problem is that Simple Ads now tries to load some of its scripts before its dependencies because it wasn't injected properly using drupal_add_js. Moehac found a solution and thankfully posted it to the issue queue:

Copy simpleads_block.tpl.php to your theme and change

  <script type="text/javascript">
    _simpelads_load('.simpleads-<?php print $tid; ?><?php if ($prefix) : ?>-<?php print $prefix; ?><?php endif; ?>', <?php print $tid; ?>, <?php print check_plain($ads_limit); ?>);