Posts Tagged ‘View Filters’

Pivot Legal – A Drupal breakdown

Colin Calnan | Tuesday, February 24th, 2009

As Melanie mentioned, we just launched a site for Pivot Legal, and a successful launch it was too. I thought I’d take a moment to give a quick breakdown of some of the tricks and wizardry we incorporated on that site.

Valid Code

For starters, we succeeded in getting most of the site to be valid XHTML, of course with Drupal there are parts where client content entry will cause some warnings and Drupals own internals will also do the same, but most of the pages on this site, within our control, are valid.

Lawyer Blogs, Resources and Events

This was the first site that we have implemented multi user blogging and user content categorization, so it was a learning experience for us. Each lawyer has their own page, in this case, that page is the default user profile page. However it’s not just your ordinary user profile page, it’s a themed user profile page. To allow us to theme this page we simply called the following function in template.php

/**
* Catch the theme_profile_profile function, and redirect through the template api
*/
function phptemplate_user_profile($account, $fields) {
	return _phptemplate_callback('user_profile', array('account'=>$account, 'fields'=>$fields));
}

Then create a template file called user_profile.tpl.php, here’s a snippet from that file:

$lawyer_profile = '<div id="lawyer_profile">'. chr(10)
   .'<h2>'. $account->profile_fullname .'</h2>'. chr(10)
   .'<h3>'. $area_of_law .'</h3>'. chr(10)
   .'<p>'. $account->profile_biography .'</p>'. chr(10)
   .'</div>'. chr(10);
// Photo, if any:
  if ($account->picture) {
    $lawyer_photo = theme('image', 	$account->picture, $account->profile_fullname .'\'s photo', $account->profile_fullname);
  }

The Blog, Resource and Events blocks on the lawyer page are simply View blocks that have the username as an argument. To achieve this we used the Usernode module to convert user profiles to nodes so that we could use their properties in views. I believe Views 2 in Drupal 6 will handle all this without the need to this module.

Username funkiness

As there are lots of users creating lots of content Drupal spits out their username attached to the piece of content (e.g “Posted by colin on Feb 26, 2009″). However on this site we wanted to show their full name and link that back to their profile page, again a simple theming function achieved this

function custom_theme_username($object) {
  if ($object->uid && $object->name) {
    // Load user so that we can get the full profile name instead of the short username
    $user = user_load(array('uid' =>$object->uid));
    $name = $user->profile_fullname;
    // If it's the "Pivot Legal LLP" user, go to the 'about-us/' page instead:
    $path = ($name != 'Pivot Legal LLP' ? 'user/'. $object->uid : 'about-us/');
 
    if (user_access('access user profiles')) {
      $output = l($name, $path, array('title' => t('View user profile.')));
    }
    else {
      $output = check_plain($name);
    }
  }
  else if ($object->name) {
    // Sometimes modules display content composed by people who are
    // not registered members of the site (e.g. mailing list or news
    // aggregator modules). This clause enables modules to display
    // the true author of the content.
    if ($object->homepage) {
      $output = l($object->name, $object->homepage);
    }
    else {
      $output = check_plain($object->name);
    }
    $output .= ' ('. t('not verified') .')';
  }
  else {
    $output = variable_get('anonymous', t('Anonymous'));
  }
  return $output;
}

Searching

It was a requirement to have a searchable directory of free legal resources on this site. We built this using a content type and Views, along with the Views Fast Search module. This allows you to create a view which acts like a search but uses view Filters to restrict the search. Robert Douglass, one of the famed Lullabots has written a great tutorial on how to set it up.

How did you get the search box on the home page?

This is pretty easy. Go ahead and create your Fast Search that we mentioned above. Then create a block and paste the following code into the body of the block, making sure to include the php tags and to set the input format to PHP:

  < ?php
  // Get the view
  $view = views_get_view('directory_search');
  // Get the filters ( in this case the search box) - this is returned as a form
  $form = drupal_retrieve_form('views_filters', $view);
  // When you submit the form make sure we go to the view page
  $form['#action'] = url($view->url);
  // Set your form up correctly in drupal
  drupal_process_form('views_filters', $form);
  // Spit the form out to screen
  return drupal_render_form('views_filters', $form);
  ?>

Of course this method can be applied to any view filters.

Views, views and more views

The rest of the site is mostly views and view blocks with some serious argument handling. The rotating images on the homepage are achieved using a simple content type for the image and then using a view to randomly load one of those pieces of content.

If you have any questions about any of the other functionality on the site or on anything I’ve menitoned above please feel free to post a comment.

 


t. 604.684.2498 | f. 604.721.4007 | e. turningheads [at] raisedeyebrow.com