Archive for the ‘Tutorials’ 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 […]

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 […]

How to plot trajectory based on inital angle and speed with jQuery and javascript

Posted on: November 3rd, 2012 by admin No Comments

I spent a long time looking for any information on this and anything I did find was too complicated for me to understand so hopefully this is a simple explanation. Fist we need to create an object to hold all our variables. 1 2 3 4 5 6 7 8 var ball = { x: […]

How to rotate a point around an origin with javascript

Posted on: November 3rd, 2012 by admin 1 Comment

Whilst this is quite simple I had trouble finding a easy to understand tutorial on this so put this up here for reference. Step 1 – Convert the angle you are rotating to from degrees to radians. To do this we just times the angle by PI and divide by 180. 1 angle = angle […]