2011
07.06

That dreadful ORA-12154 error

I lost hours trying to resolve this:

“ORA-12154: TNS:could not resolve the connect identifier specified”

It requires lots of determination not to swear and rant about the possible causes of this message but in my case (Windows 7 64bits), it turns out that Toad doesn’t like to be installed in a folder with ‘()’s like ‘C:\Program Files (x86)’

I installed in C:\Toad\ and the problem is resolved.

Of course to reach there I had to resolve some other issues (for the same error message) like:
– Installing 32bits version of Oracle Client (10.2.0.1)
– Instant client didn’t work for me.

Hope it helps.

Author: (8)

2011
07.06

Finish UI first

If you are one of those unlucky guys who have to live in both worlds, design/develop the front end, and the server side functionality and test, and … you got me… I find it quite effective to start and finish a fully functional UI first than start coding the back end.
* By fully I mean the 80%-20% fully.
* Even if you write some mock-up code to mimic your biz logic related objects, it’s OK, and takes generally less time than you think to throw away the prototype and replace it with the real stuff.
* This might be a personal trait/flaw, but having something visual in front of me helps me to understand the problem better.

Author: (8)

2010
03.04

If your hosting is providing you shell access, Drush (Drupal Shell) is a blessing if you want to make some repetitive actions faster, easier and more robust. The installation bit might be a little scary for new users (especially if it is the first time you hear the terms shell, bash, etc.) but it is definitely worth the effort.

With drush, among many many other things (e.g. install, update, enable/disable contributed modules), you can also:

backup (mysql dump) your database

    $ drush sql dump --result-file=backup.sql

reload/copy (mysql load) your database (some_database)

    $ drush sql connect #connect to MySQL via Drush
    $ mysql some_database < backup.sql #load file into database

Source: Nathan Rambeck

Author: (16)

2010
02.24

dijit startup()

Here is something that I keep forgetting all the time.
Lifecycle methodstartup()is called for widgets in template, but not for your programmatically created widgets. So for them, you have to call it manually after creating the widget.

Author: (8)

2010
02.13

Redirect to the referring page after login in Drupal

Redirection might become a little problematic if you are not sure how to do it in Drupal. You can add at the end of your link ?destination=redirect/here but either the link might not work properly for some reason or you might prefer the referrer page to be dynamic.

Here is the solution:

$destination = drupal_get_destination();
print l('Login', 'user/login', array('query' => $destination));

Source: cglusky

Author: (16)

2010
02.06

In Drupal, when you create a select field and you make that field required, you are very likely to run into a weird issue.

The required field will get the first value of the list, making it very easy for the user to overlook it. If the user overlooks it, there is a high probability the first value will not be the correct one. Putting an empty first value does not work as well, as Drupal will just ignore it.

This is actually an easy problem to tackle but the answer might be a little difficult to find. First you should now that you can differentiate the label and the value while configuring the select list. The convention is value|label.

To solve our problem, we are just going to use null value for the first value of the select list. For example |-- Please select --

So a required language list will be something like this. The first value being empty will make Drupal ask for something else if left untouched:

|-- Please select --
Français|French
Italiano|Italian
Deutsche|German

PS: You do not have to use labels for other values

Source: grendzy

Author: (16)

2010
01.29

“Login or register to vote” snippet for Fivestar module in Drupal

VotingAPI and Fivestar function very well if you want to implement a voting widget and all necessary functionalities that comes with it.

When I wanted to implement “Login to Vote” functionality -voting widget behaving similar to the comments for anonymous users-, I came across the following snippet which works flawlessly. Just rename [nameofyourtheme] to your theme name (without []) and insert it in your template.php file and you are good to go.

<?php
/**
* Display a static fivestar value as stars with a title and description.
*/

function [nameofyourtheme]_fivestar_static_element($value, $title = NULL, $description = NULL) {
  $output .= '<div class="fivestar-static-form-item">';
  $element = array(
    '#type' => 'item',
    '#title' => $title,
  );

  $output .= theme('form_element', $element, $value);
  $output .= '<div class="description">'. t('Login or register to vote.') .'</div>';
  $output .= '</div>';
  return $output;
}
?>

Source: quicksketch

Author: (16)

2010
01.28

It might be very convenient to create a page with PHP-filter and then insert a drupal_goto function to divert the user according to the conditions (e.g. logged-in, role ).

However, you should be careful not to break Cron with drupal_goto. As cron will get stuck trying to index your page with drupal_goto function.

In order to prevent this you can check for the $_SERVER['SCRIPT_NAME']. For example:

if ($_SERVER['SCRIPT_NAME'] != '/cron.php') {
       drupal_goto('someplace/in/your/website');
     }

Author: (16)

2010
01.25

Two useful snippets for block visibility in Drupal

Here are two very useful snippets that you should keep somewhere easy to access and safe:

To display the block ONLY on Node View but not on Node Edit:

<?php
// Only show on true node VIEW pages. Not node/add or node/n/edit etc
return (arg(0)=='node' && is_numeric(arg(1)) && (!arg(2)));
?>

The same principle works with ‘user’ as well if you want the block to show only in user profile but not in registration, request password screens.

Source: Drupal PHP snippets

To display the block ONLY on logged-in user's account page but not on other user's account page:

<?php
global $user;
// Return TRUE if we have a user viewing her/his own user profile.
return $user->uid && arg(0) == 'user' && is_numeric(arg(1)) && arg(1) == $user->uid;
?>

by Nedjo

Author: (16)

2010
01.19

Creating profile picture block in Drupal

Even though, it is quite easy to figure it out with a little PHP and Drupal knowledge, it might still be frustrating for beginners to find an easy answer for this question.

Try creating a block with the following PHP code (do not forget to select the PHP code as input format):

<?php
$owner = user_load(arg(1));
print theme('user_picture', $owner);
?>

Most probably, you will want to limit the visibility of the block to user/* and/or users/* (if you are using pathauto module).

Source: dalad’s comment

Author: (16)