Skip to main content

Working with Drupal

Drupal is an open source Content Management System (CMS) built in PHP. It is used by a wide variety of websites from large corporates through to smaller startups. Drupal is hugely flexible which is what makes it such a great framework around which to build almost any type of website. At ComputerMinds we are a Drupal only development house so Drupal is all we do, all day, every day. To find out more about Drupal and how it can work for you have a look at some of our Drupal articles below and feel free to explore our site further to see how ComputerMinds might be able to help you realise your web goals.

Read some of our articles about Drupal

Customising the Drupal search block form

16th Dec 2007

The Drupal search block form is one of those things that gets used in most themes, and frequently needs a bit of themeing to bring it in line with your target design.

The following snippet (which needs to live in your template.php file) will change the word "Search" in the submit button to "Go", and will add a title to the search terms box ...


function phptemplate_search_block_form($form) { 
  $form['search_block_form_keys']['#title']='search the site';
  $form['search_block_form_keys']['#size']=10;  
  $form['submit']['#value']='GO!';
  return drupal_render($form);
}
Read more

Allowing unfiltered content on the Drupal contact page

16th Dec 2007

The contact page exposed by the Drupal contact module is great, it allows you to put together a contact form quickly and easily. But there is one small(ish) problem, the header text for the form is being filtered - which prevents you from using certain tags (for example embed). We found this problem when trying to embed a youtube movie onto the drupal contact form.

The solution is a little bit of themeing - put the following in your template.php file, you will have to be a bit carefull as your now not filtering your output - so you HAVE...

Read more

Drupal - Fatal error : allowed memory size exhuasted

13th Dec 2007

One of the classic Drupal problems that catches a lot of newbies out is the memory error exhausted error. Typically you get this on the modules page - but it could appear almost anywhere.

Its nothing much to worry about and can be easily solved by following the advice posted here http://drupal.org/node/76156

Read more

Fix Drupal fieldset titles disappearing in firefox

11th Dec 2007

You may have spotted that for some Drupal themes in some versions of Firefox the titles on fieldsets are sometimes not there ...

This little CSS snippet should solve the problem ...

fieldset legend {display:block; }

Read more

Adding text to the Drupal feed icon

10th Dec 2007

Drupal's handling of RSS's feeds is generall excellent, BUT sometimes it's nice to add a bit of explanation text to the standard orange feed icon.

Add this little snippet to your template.php file and you can add a bit of text to your Drupal feed icon.


function phptemplate_feed_icon($url) {
    if ($image = theme('image', 'misc/feed.png', t('Syndicate content'), t('Syndicate content'))) {
        return ''. $image. ' RSS feed';
    }
}
Read more

Adding custom markup to Drupal menu items

10th Dec 2007

There are times when it's necessary to add some additional markup to a particular menu item, for example a link to DrupalMinds might need a strong tag around the Drupal portion.

This can be achieved in a couple of ways, both using a very similar theme override.

Option 1

The first method is to allow HTML in the title of all menu items - while this is nice and easy, it does mean that you have to manually escape special characters, such as quotes and pound signs. The code is below:


function phptemplate_menu_item_link($item, $link_item) {
  return l($item['title'], 
           $link_item['path'],

           !empty($item['description'])...
Read more

Drupal - changing the calander view to display single letter for day of the week

30th Nov 2007

By default the Drupal event module will provide a nice calander block, listing the days of the week accross the top using 3 letter abbreviations (mon, tue etc).

This little theme snippet will override this default behaviour and display the first letter of each day of the week (i.e. M T W) etc.

Pop the following into your template.php file and you should be in business


function phptemplate_event_calendar_month($op, $header, 
$rows, $attributes = array(), $caption = NULL) {
  //run through each item in the old header and just use the first letter 
//instead of the entire word
  foreach ($header as $item){...
Read more

Removing tinymce from textareas

13th Nov 2007

TinyMCE has a habit of popping up right where you don't want it - the log field on a node edit page is a good example.

Lucklily it is a relatively easy job to theme out tinymce for a particular textarea.

The following theme override should go into your template.php file



function phptemplate_tinymce_theme($init, $textarea_name, $theme_name, $is_running) {
  switch($textarea_name){
    case 'nodewords-description':
      case 'edit-nodewords-description':
	unset($init);
	return $init;
      break;
      default:
	return theme_tinymce_theme($init, $textarea_name, $theme_name, $is_running);
  }
}

Just keep adding extra cases for any additional textareas ...

You might also be interested in this article about removing tinymce from the block edit screen...

Read more

Adding an active class to the Drupal primary links

8th Nov 2007

One of the most annoying things about developing a Drupal theme is the lack of an 'active' class on your primary links. By default the primary links are given a class of menu-X-Y-Z-active if they are active. From a theming point of view, this is next to useless, you need a nice standalone active class on your primary links.

So - here is a very simple snippet for your template.php file ...


function _phptemplate_variables($hook,$vars){
  if ($hook=='page')
    if ($vars['primary_links']){
      foreach ($vars['primary_links'] as $key=>$link){
        if (strpos($key,'-active')){
          $vars['primary_links'][$key]['attributes']['class'].=' active';
        }
      }
    }
  }
}

And thats it - nice and simple, you should...

Read more

Tinymce width problems - CSS snippet

8th Nov 2007

We have had a few sites recently on which TinyMCE was playing up on narrow themes. The buttons where not breaking onto new lines, causing the TinyMCE textarea to be much too wide.

We solved the problem with the following snippet of CSS


.mceToolbarTop * {
    float:left;
}

.mceToolbarTop select {
    width:auto!important;
}

.mceToolbarTop option {
    float:none;
}
Read more