views, arguments, panels
TRANSCRIPT
Views, Arguments, Panels
Darko [email protected]
Welcome
• Me– Drupalist– Developer– Teacher
• Agentic– Growing web shop with a social mission– www.agentic.ca
Information architecture => Drupal
• “The art and science of organizing and labeling web sites, intranets, onlinecommunities and software to support findability and usability.”
• How to satisfy the IA?
Drupal module alchemy
• The magical combination of modules that will do x or y• Example sites (in development)
– Ecotrust Canada (IA and creative by Biro Creative)
– Untape (IA by Social Signal, creative by Agentic/Social Signal)
• Top x Drupal modules– http://www.nicklewis.org/node/766– Lullabot’s list
• CCK, Views, Panels
The URL
• Clean url’s• path module• arg()
– mysite.com/node/23– mysite.com/myview/23– Node with path alias ‘best-blog-ever’
• arg(0) = ‘node’
$path = explode('/', drupal_get_path_alias($_GET['q'])); // getthe current path, lookup the path_alias and turn the pieces itinto an array (from http://drupal.org/node/70145)
Views
• http://drupal.org/project/views• Advanced query builder• A page that shows a bunch of nodes based on certain
criteria• Built-in views: taxonomy/term/X• Custom views: myview
Creating a simple view
• Top 5 blog posts
Views arguments
• Our view has a path alias• Everything after that path is an argument
– mysite.com/myview/23– yearly/monthly blog archive
Taxonomy terms insections/subsections
• Ecotrust– Rainforest
• Mapping• Forestry
– Ocean• Mapping
– Climate• Mapping
• Problem with duplicate taxonomy names (pretty, but id’sare less troublesome)
Views argument handling code
• http://drupal.org/node/70145• Modify (or derive) argument(s) into something the view
can use• $args versus arg()• Example: adding taxonomy title (Untape)• Example: contact_block (Ecotrust)
– This is a view block that filters based on arg(1)– Because it’s a block, we need to pass arg(1) back to it with arg
handling code// Make the first argument based on what arg(1) is// eg. program_area/rainforest/mapping should return rainforestif (!$args[0]) {$args[0] = arg(1);}return $args;
The “two taxonomy terms” problem
• Views cannot filter two taxonomy terms• Taxonomy ID’s are ok
– taxonomy/term/1,2 (AND condition)
• Feed the ID’s to the view with argument handling code• Example - Ecotrust
– program_area/rainforest/mapping
http://www.ecotrust.dev/admin/build/views/overview_two_terms/edit
// Blake Edwards Arugment Handling Code// - Multiple Taxonomy Term Names as Arguments// $exclude_vocab = array('13');$exclude_vocab = array();
if ($args[0]) {//replace underscores with spaces// Darko - process the url directly, because the view can't seem to get its arguments from the panel$args[0] = arg(1);$args[1] = arg(2);if ($args[0]!='' && $args[1]!='') { // ie this view requires two taxonomy name arguments// Darko - end direct url processing modificationforeach ($args as $key=>$arg) {$args[$key] = str_replace('_',' ',$arg);}$args_original = $args;$args_processed = array();foreach ($args as $key=>$arg) { if (!is_numeric($arg) || strlen($arg) == 4) { $terms = taxonomy_get_term_by_name($arg); //do a search for terms, return term objects if (count($terms) > 1) { //Exclude Vocabularies foreach ($terms as $key=>$term) {if (in_array($term->vid,$exclude_vocab)) {unset($terms[$key]);}} } array_push($args_processed,$terms[0]->tid); } else { array_push($args_processed,$arg); }}
//Flatten Array to one Argument Comma Separatedforeach ($args_processed as $arg) { $newargs .= "$arg,"; }$newargs = substr($newargs,0,-1);
return array($newargs);}}
Handling code for processing two term name arguments
Set the views args towhat’s in the url
The rest of the codeconverst the termnames to a commaseparated term id listso the view canprocess them
Argument handling code examples
• http://drupal.org/node/70145
• End of presentation due to time constraint• Panels information was left for Gregory Heller’s
presentation on Panels2
Panels
• Collection of blocks, views, nodes• Complicated home pages, user profiles, etc.• Panels can pass arguments to views• Caveat - block visibility for views-created blocks
Creating a panel
• Simple example of /home panel• Site information: Default front page = home
Example: “blocky” home page
• Untape
Example: “blocky” user profile
• myUntape versus contributor panel
QA