Drupal Development
Dec. 02, 2013

Going Grandpa Style with Drupal

As most of you hardcore Drupalers already know, there's either, "a module for that" or a "Drupal Way" to do just about anything you would ever want to do on a drupal site or application. I’m relatively new to drupal module writing (about 1 ½ years). I’m learning every day and get pretty excited when I pull something new off.

I currently have a client that wants people to return to the last page they have viewed when they return to the site regardless of whether they’re logged in or not.
Sounds like a job for cookies right? Right. So, I fire up Google.

I’ve been doing web stuff since the 90’s and I’ve found that with web development (and pretty much anything else for that matter) Occam’s Razor or “Keep it Simple, Stupid” is usually the way to go.

But sometimes, finding that simple solution proves harder than implementing it. I’m sure most of you have read threads on d.o  and stackexchange that begin with, “I’ve been beating my head against the wall for days trying to…”. It didn’t take me days but a few hours later I finally found (and can’t exactly remember how):

user_cookie_save(array('key'=> 'value'));

Where key is Drupal_visitor_key and the value can be anything you assign. I set the value using $_SERVER['REQUEST_URI'] and then used drupal_goto() to redirect the user based on the cookie value when they come to the homepage of the site or login.

The fact remains, there usually is a simple Drupal solution out there, you may just have to work really hard to find it. Don’t, I repeat don’t, overthink it. Instead, try asking yourself, “What would my Mama do?” (My mama is in her 60’s and is just now starting to use email and facebook as a result of her recent switch from dial-up to cable.)
Because she doesn’t have years of search experience under her belt, the answer that I arrive at usually leads me to the simple solution, which she is certainly searching for.

Something as easy as making up function names can get you right where you need to go. I believe the search that yielded the answer I needed was when I typed, “hook_cookie_save drupal 7” into the address/search (awesome?) bar.
Or try typing your exact scenario into search - like
this guy .

Drupalers are smart but sometimes we just need to get out of our own way and think like a senior citizen when looking for a solution.


Add new comment

Benji Damron

Stay in the Loop.

Sign up to recieve our best content monthly: