alcali asked: Great post! Any idea how to get the total count when you have multiple page result? thanks
Hmm… I don’t actually, but that seems like something important I’ve neglected. I’ll look into it when I get some free time, but if you figure it out first please share the method with me!
Showing the number of results a search returns in Drupal 7

Ok ducklings, Drupal 7 can be a huge turd when it comes to some things. Today I came across one of those things.
The boss handed me a search result page design that included a “Showing x results” element. I bet you can guess that Drupal doesn’t do that with any available hook function or available variables/constants.
Searches in D7 can be themed from two files, search-results.tpl.php and search-result.tpl.php. The first themes the results of the second which themes individual search results. Handy!
Sadly, like I mentioned earlier, there’s no default function for what I want to do so I had to use a template_preprocess_search_results() function in my template.php file. Make sure if you’re going to copy my code that you replace the word “template” in that function with the machine name of your theme.
function yourtheme_preprocess_search_results(&$variables) {
$variables['search_results'] = '';
if (!empty($variables['module'])) {
$variables['module'] = check_plain($variables['module']);
}
$search_count = array();
foreach ($variables['results'] as $result) {
$search_count[] = $result;
$variables['search_results'] .= theme('search_result', array('result' => $result, 'module' => $variables['module']));
}
$search_count = count($search_count);
$variables['count'] = $search_count;
$variables['pager'] = theme('pager', array('tags' => NULL));
$variables['theme_hook_suggestions'][] = 'search_results__' . $variables['module'];
}
This is pretty much the same as the standard version of the function except that I created an empty array, and then populated it with results in that foreach() function. Then I used PHP’s count() to see how many keys were in the array. That’s the number of results.
The last part, $variables[‘count’] is the special piece which makes it available in the search-results.tpl.php file. So in that file, I can just print $count anywhere and blamo, I have a display of the number of results of a search.
Putting a Paypal link into a form loaded with colorbox using Drupal 7’s FAPI

I hope my face relays the angst involved with this concept.
Here’s what I wanted out of Drupal today:
- Have a main menu item load in a modal popup (Colorbox) instead of directing you to a page.
- Specifically, load the contact form link as a popup (and maybe newsletter subscriptions as well).
Apparently this is a huge pain in the assbutt.
Here’s how to do it:
- Crack open your theme.template file and add something like this in your theme_preprocess_page() with drupal_add_js in your doc ready function:
jQuery("#menu-532-1 a").attr("href","http://yoursite.com/colorbox/form/form_id?width=500&height=500&iframe=false#form_id").colorbox();
- Thank your lucky stars you didn’t dick around with this for hours.
Something to note is that this will not work for forms other than Contact, User Register/Login and a few others. Webforms and the like require a highly more annoying solution involving adding the form block to an invisible region in the template and then pulling the form into colorbox manually with jquery. It doesn’t look pretty and also isn’t the focus of this — so back to the matter at hand.
Now is the trickiness - I needed to add some stuff to that popup, but the way I did it I was only loading the form itself, which means I needed to modify the form with Drupal’s awesome Forms API (FAPI).
I created a module called “helper” to store my hooks and added this:
function helper_form_contact_site_form_alter(&$form, &$form_state, $form_id){
$form['some_text'] = array(
'#type' => 'item',
'#markup' => '<p>markup</p>',
);
}
Ok, yeah, that was easy. But now I need a Paypal donation link. Typically these come as forms that you copy/pasta into your site. But you can’t hook a form into another form, that’s stupid.
Here’s a link structure you can use in a form field’s #markup:
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=you@whatever.com&item_name=Item%20Name%20With%20Spaces"><img src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" /></a>
Turns out I like mobile photography. Ive seen some shots on flickr recently that could rival some shots taken with an SLR.
Even more hipster goodness because of the cat. The application is called Pixlr-o-matic. It has basic color filters and light filters though it still seems like it’s playing catch up to instagr.am
Something it does seem to have going for it is the ability to share photos that are actually quite large.
Consolidating gmail addresses
I have 3 email addresses I use for different things: (example) work@gmail home@gmail freelance@gmail.
I also happen to hate every mail client except Sparrow which I can’t use since I’m an Arch Linux guy. Most days I have 3 pinned tabs in Chrome for each email account.
To make my life easier I consolidated them all into one account (my home@gmail address).
Here are the steps:
- In the main account, head to your mail settings page and choose “Accounts & Import.”
- Click “Add another email address you own” and follow the steps to add the address. Make sure to click “Treat as alias.”
- On the second step choose “Send through yourdomain.com SMTP servers” and set the address value to smtp.gmail.com (assuming you’re using another gapps email) or your smtp server. This will remove the “on behalf of” header that would normally get sent.
- In the sub email account, head to your mail settings page and choose “Forwarding and POP/IMAP.”
- Set up your main account as a forwarding address. This will send an email to your main account with a link you need to click to confirm the forwarding.
- Close all those darn tabs and enjoy your consolidated email world.
Now all your emails should go into the same inbox and depending on how you set it up, you’ll either have a copy in your sub account inboxes or nothing at all. You can reply and send emails from your sub accounts within your main account by choosing an address from the dropdown on the from field in emails.



