Drupal Views: Show count

The view results count is stored in the view object and you can display it by adding a PHP header or footer to your view. In order to have PHP in views you need the module Views PHP, so install it first then add a header or footer with this code. <?php // Dispaly count… Continue reading Drupal Views: Show count

Drupal: Send email

This is a quick and easy solution to send an email from Drupal using PHP, i.e a custom module. you will do it in 2 steps (I assume your module is called “mod”): Define mod_mail() (implementing hook_mail() ), this function will prepare the email Send the email using drupal_mail() Define mod_mail() /** * Implementation of… Continue reading Drupal: Send email

Drupal 7: Get files public directory path

We used to get the files directory using file_directory_path() in Drupal 5 and 6, the function was removed with Drupal 7 but you can still get the files public directory like this: echo variable_get(‘file_public_path’, conf_path() . ‘/files’); // Outputs: sites/default/files

Drupal : Get path and verify if it’s an alias

This is how I get the current path and/or alias in Drupal: After this code has been executed: $path will hold the internal drupal path $alias will hold that path alias if the path in the url is actually an alias, otherwise FALSE; $path_from_url = isset($_GET[‘q’]) ? $_GET[‘q’] : ”; $path = drupal_get_normal_path($path_from_url); if($path ===… Continue reading Drupal : Get path and verify if it’s an alias

Fix “xyz.widget is not a function” when jQuerying in Drupal

The error looks like: c.widget is not a function Or: d.widget is not a function I get this error when I do theming or module development for Drupal. Basically this tells you that the file jquery.ui.widget.js is missing. check the code you were writting and add that file to Drupal like this: drupal_add_js(‘misc/ui/jquery.ui.widget.min.js’);

Classical Gnome in Ubuntu 11.10 (Oneiric Ocelot)

Install necessary packages In order to have Gnome classical appearance on Ubuntu 11.10 you need to install gnome-shell and gnome-panel, a following reboot -from my experience – is preferable. imame@meta:~$ sudo apt-get install gnome-shell gnome-panel imame@meta:~$ # blabla while packages are being installed imame@meta:~$ sudo reboot Log in using Gnome Classical Before opening your session,… Continue reading Classical Gnome in Ubuntu 11.10 (Oneiric Ocelot)

PHP: remove an array item by value

It isn’t quite obvious to remove an array item when all you know is the value of that item, – i.e. you don’t now the item index. Remove items without preserving original indexes $the_array = array_values(array_diff($the_array,array($the_value))); // Example $the_array = array(‘A’, ‘B’, ‘B’, ‘C’); $the_array = array_values(array_diff($the_array,array(‘B’))); /* Original array: [0] => A [1] =>… Continue reading PHP: remove an array item by value