views, arguments, panels

19
Views, Arguments, Panels Darko Hrgovic [email protected]

Upload: hadiep

Post on 22-Dec-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Views, Arguments, Panels

Views, Arguments, Panels

Darko [email protected]

Page 2: Views, Arguments, Panels

Welcome

• Me– Drupalist– Developer– Teacher

• Agentic– Growing web shop with a social mission– www.agentic.ca

Page 3: Views, Arguments, Panels

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?

Page 4: Views, Arguments, Panels

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

Page 5: Views, Arguments, 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)

Page 6: Views, Arguments, Panels

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

Page 7: Views, Arguments, Panels

Creating a simple view

• Top 5 blog posts

Page 8: Views, Arguments, Panels

Views arguments

• Our view has a path alias• Everything after that path is an argument

– mysite.com/myview/23– yearly/monthly blog archive

Page 9: Views, Arguments, Panels

Taxonomy terms insections/subsections

• Ecotrust– Rainforest

• Mapping• Forestry

– Ocean• Mapping

– Climate• Mapping

• Problem with duplicate taxonomy names (pretty, but id’sare less troublesome)

Page 10: Views, Arguments, Panels

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;

Page 11: Views, Arguments, Panels

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

Page 12: Views, Arguments, Panels

// 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

Page 13: Views, Arguments, Panels

Argument handling code examples

• http://drupal.org/node/70145

Page 14: Views, Arguments, Panels

• End of presentation due to time constraint• Panels information was left for Gregory Heller’s

presentation on Panels2

Page 15: Views, Arguments, Panels

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

Page 16: Views, Arguments, Panels

Creating a panel

• Simple example of /home panel• Site information: Default front page = home

Page 17: Views, Arguments, Panels

Example: “blocky” home page

• Untape

Page 18: Views, Arguments, Panels

Example: “blocky” user profile

• myUntape versus contributor panel

Page 19: Views, Arguments, Panels

QA