Custom view : panels, list in 2 columns

116_butterfly - July 3, 2007 - 16:54
Project:Views Bonus Pack
Version:5.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hello !
I'm trying to create a custom plugin for the views bonus pack, containing 2 columns of a list view.
I took the panels_twocol.inc, renamed it panels_twocol_list.inc and enabled it in the admin section.

Here's my code:

<?php
function views_bonus_panels_twocol_list_info() {
 
$items['panels_twocol_list'] = array(
   
'name' => t('Panels: Lists, 2 columns'),
   
'description' => t('Show views as lists in two columns.'),
   
'requires' => array('panels'),
  );
  return
$items;
}

function
views_bonus_panels_twocol_list_style_plugins() {
 
$items['panels_twocol_list'] = array(
   
'name' => t('Panels: Lists, 2 columns'),
   
'theme' => 'views_bonus_panels_twocol',
   
'summary_theme' => 'views_summary',
  );
  return
$items;
}

/**
* Because views doesn't currently support configuration options for
* plugins, the best way to make configuration changes here is
* to override the theme.
*/
function theme_views_bonus_panels_twocol_list($view, $nodes, $type) {
 
$teasers = true;
 
$links = true;
  if (!
module_exist('panels')) {
   
//return theme('views_view_nodes', $view, $nodes, $type, $teasers, $links);
   
return theme_views_view_list($view, $nodes, $type);
  }
 
$content = array();
  foreach (
$nodes as $count => $n) {
   
$node = node_load($n->nid);
    if (
$count % 2) {
     
$section = 'right';
    }
    else {
     
$section = 'left';
    }
   
//$content[$section] .= node_view($node, $teasers, false, $links);
   
$content[$section] .= "<a href='/node/" . $node->nid . "'>" . $node->title . "</a><br />";
  }
  return
panels_print_layout('twocol', $content);
}
?>

Unfortunately, my function theme_views_bonus_panels_twocol_list is not read by drupal and the view is displayed like the panels_twocol.inc template, with teasers instead of a list of titles...
I've taken example on this thread http://drupal.org/node/100329 but I can't find where's the difference...

Thanks for your help...

#1

dmitrig01 - July 6, 2007 - 03:23

Thanks for taking part in useing views_bonus!
You should be able to make it work with

<?php
function views_bonus_panels_twocol_list_info() {
 
$items['panels_twocol_list'] = array(
   
'name' => t('Panels: Lists, 2 columns'),
   
'description' => t('Show views as lists in two columns.'),
   
'requires' => array('panels'),
  );
  return
$items;
}

function
views_bonus_panels_twocol_list_style_plugins() {
 
$items['panels_twocol_list'] = array(
   
'name' => t('Panels: Lists, 2 columns'),
   
'theme' => 'views_bonus_panels_twocol_list',
   
'summary_theme' => 'views_summary',
  );
  return
$items;
}

/**
* Because views doesn't currently support configuration options for
* plugins, the best way to make configuration changes here is
* to override the theme.
*/
function theme_views_bonus_panels_twocol_list($view, $nodes, $type) {
 
$teasers = true;
 
$links = true;
  if (!
module_exist('panels')) {
   
//return theme('views_view_nodes', $view, $nodes, $type, $teasers, $links);
   
return theme_views_view_list($view, $nodes, $type);
  }
 
$content = array();
  foreach (
$nodes as $count => $n) {
   
$node = node_load($n->nid);
    if (
$count % 2) {
     
$section = 'right';
    }
    else {
     
$section = 'left';
    }
   
//$content[$section] .= node_view($node, $teasers, false, $links);
   
$content[$section] .= "<a href='/node/" . $node->nid . "'>" . $node->title . "</a><br />";
  }
  return
panels_print_layout('twocol', $content);
}
?>

#2

dmitrig01 - July 6, 2007 - 03:24
Status:active» fixed

#3

116_butterfly - July 6, 2007 - 11:33

Thank you dmitrig01 !
It was a stupid mistake, and I'm ashamed not to have seen it by myself :-)

#4

Anonymous - July 20, 2007 - 11:46
Status:fixed» closed

#5

vthirteen - January 20, 2008 - 20:30
Version:4.7.x-1.x-dev» 5.x-1.0
Status:closed» active

reopen to know if this code works in the drupal 5 version of the module.

- i duplicated and renamed the file two_col.inc as two_col_list.inc under panels/layouts
- i added some code to views_bonus_panels.module:

  $items['panels_twocol_list'] = array(
    'name' => t('Panels: List, 2 columns'),
    'theme' => 'views_bonus_panels_twocol_list',
    'summary_theme' => 'views_summary',
  );

(even though i could have simply put the modified function within my template.php)

i can see the new option in views creating/editing form but it produces an error:

Fatal error: Call to undefined function module_exist() in /[path-to-drupal-root]/sites/all/themes/[mytheme]/template.php on line 138

which corresponds to the follwing function:

function [mytheme]_views_bonus_panels_twocol_list($view, $nodes, $type) {
  $teasers = true;
  $links = true;
  if (!module_exist('panels')) {
    //return theme('views_view_nodes', $view, $nodes, $type, $teasers, $links);
    return theme_views_view_list($view, $nodes, $type);
  }
  $content = array();
  foreach ($nodes as $count => $n) {
    $node = node_load($n->nid);
    if ($count % 2) {
      $section = 'right';
    }
    else {
      $section = 'left';
    }
    //$content[$section] .= node_view($node, $teasers, false, $links);
    $content[$section] .= "<a href='/node/" . $node->nid . "'>" . $node->title . "</a><br />";
  }
  return panels_print_layout('twocol', $content);
}

i will really appreciate any help! thank you

#6

vthirteen - January 20, 2008 - 20:42

ok, i panicked too quickly.
the error was pulled out by a change in drupal that i did not notice:

module_exist('panels')

has to be changed to:

module_exists('panels')

#7

vthirteen - January 20, 2008 - 20:52
Version:5.x-1.0» 5.x-1.x-dev

now, i have thise piece of code in my template.php:


function theme_views_bonus_panels_twocol_list($view, $nodes, $type) {
  $teasers = true;
  $links = true;
  if (!module_exist('panels')) {
    //return theme('views_view_nodes', $view, $nodes, $type, $teasers, $links);
    return theme_views_view_list($view, $nodes, $type);
  }
  $content = array();
  foreach ($nodes as $count => $n) {
    $node = node_load($n->nid);
    if ($count % 2) {
      $section = 'right';
    }
    else {
      $section = 'left';
    }
    //$content[$section] .= node_view($node, $teasers, false, $links);
    $content[$section] .= "<a href='/node/" . $node->nid . "'>" . $node->title . "</a><br />";
  }
  return panels_print_layout('twocol', $content);
}

point is that it does not print any of the fields i set up in the view that i want to be displayed in two columns. it just prints the linked title (ignoring drupal's baseurl, so the link is also wrong).

it just does not take the view's fields into consideration and i can actually set the views to be displayed as 2 col list without setting up any list field, which is something that views always prevents you to do.

any help very much appreciated!

#8

dmitrig01 - January 26, 2008 - 04:17
Project:Views Bonus Pack» Views
Version:5.x-1.x-dev» 5.x-1.x-dev

Re-assigning to proper queue

#9

sun - September 13, 2008 - 15:05
Project:Views» Views Bonus Pack
Version:5.x-1.x-dev» 5.x-1.x-dev

@dmitri: Please have a look at the issue queue - Views maintainers are buried already. Just moving an issue to Views' queue without any additional information why this would be an issue with Views won't help anyone. In front of moving an issue in here, please check the queue for already existing issues.

 
 

Drupal is a registered trademark of Dries Buytaert.