Archive for the ‘Drupal 7’ Category

Automatically add a field to every new webform created

Posted on: October 30th, 2013 by admin 1 Comment

I recently had a need for users to be able to attach webforms to some node types to allow users to give feedback. Each webform could be attached to multiple nodes. When the webform data was submitted it needed to record which node it was attached to. This was easy enough by adding a hidden […]

Drupal Form with dynamically adding a collection of fields via ajax

Posted on: October 25th, 2013 by admin No Comments

I put this together by combining a couple of different examples from the examples module but wanted to keep it here for future reference. This example shows a holiday form where each holiday has a start date, end date and number of days field, and there can be multiple holidays. 1. Set up the page: […]

Add a class to each of Drupal 7 primary tab items

Posted on: October 18th, 2013 by admin 2 Comments

If you find yourself wanting to style each tab individually, or attaching a certain JavaScript attributes to a particular tab this this code is very useful. Just put this in your themes template.php. function YOUR_THEME_NAME_menu_local_tasks(&$variables) { if (isset($variables[’primary’])) { foreach($variables[’primary’] as $menu_item_key => $menu_attributes) { $variables[’primary’][$menu_item_key][’#link’][’localized_options’][’attributes’][’class’][] = strtolower(str_replace(’ ‘,’-‘, $menu_attributes[’#link’][’title’])); } } return theme_menu_local_tasks($variables); }function […]

Add “Delete All Terms” button to Drupal 7 Vocabulary Page

Posted on: October 10th, 2013 by admin No Comments

Sometimes it is necessary to delete all terms from a taxonomy however Druapl does not provide any functionality to do this. I’m using the jQuery Easy Confirm Dialog plugin for this. First download the library from here and put this in your themes js folder. We can then add a “Delete All Terms” button with […]

Create a new join in hook_views_query_alter

Posted on: October 8th, 2013 by admin 4 Comments

I tried to do this recently and found very few examples available online so am putting this up here for reference. My original query looked like this: 1 2 3 4 SELECT node.title, node.nid FROM node node WHERE node.status = ‘1’ AND node.type IN (’resource’) ORDER BY node_title ASCSELECT node.title, node.nid FROM node node WHERE […]

Drupal urlencode and Drupal urldecode

Posted on: February 7th, 2013 by admin No Comments

In Drupal when even I try to urlencode a url and pass it as an argument to a function then I get the error Not Found. It seems drupal does like the forward slashes, even if they are url encoded. To get round this I’ve written these two functions: 1 2 3 4 5 6 […]

Example of a complex dynamic query with subqueries in Drupal 7

Posted on: February 6th, 2013 by admin 2 Comments

I often find it hard to find good examples of Drupal 7 dynamic queries – especially when you are joining on to dynamically created tables so have put this up here for reference: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 […]