| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
require_once(drupal_get_path('module', 'simplelist') .'/SimpleListDisplayParent.php');
|
| 5 |
|
| 6 |
/**
|
| 7 |
* This display class takes a list of nodes, and presents them to the user in an unordered list.
|
| 8 |
*
|
| 9 |
*/
|
| 10 |
class SimpleListDisplay extends SimpleListDisplayParent {
|
| 11 |
|
| 12 |
/**
|
| 13 |
* The render function takes an array of nodes and presents them in an unordered list based on the simplelist data.
|
| 14 |
*
|
| 15 |
* @param stdClass $simple_list
|
| 16 |
* Simplelist
|
| 17 |
* @param array $node_array
|
| 18 |
* Array of node objects
|
| 19 |
* @return string
|
| 20 |
* HTML to present
|
| 21 |
*/
|
| 22 |
public function render($simple_list, $node_array) {
|
| 23 |
$items = array();
|
| 24 |
|
| 25 |
foreach($node_array as $node) {
|
| 26 |
if ($simple_list->display->display_format == SIMPLELIST_FORMAT_TITLE_LINK) {
|
| 27 |
$items[] = l($node->title, 'node/'. $node->nid);
|
| 28 |
}
|
| 29 |
else if ($simple_list->display->display_format == SIMPLELIST_FORMAT_THEME) {
|
| 30 |
$items[] = theme(array("simplelist__$simple_list->name", "simplelist"), $node, $simple_list);
|
| 31 |
}
|
| 32 |
else if ($simple_list->display->display_format == SIMPLELIST_FORMAT_TEASER) {
|
| 33 |
if (isset($node->teaser) && isset($node->body)) {
|
| 34 |
$items[] = node_view($node, TRUE, FALSE, FALSE);
|
| 35 |
}
|
| 36 |
else {
|
| 37 |
$items[] = theme('node', $node, TRUE, FALSE);
|
| 38 |
}
|
| 39 |
//dprint_r($items);
|
| 40 |
}
|
| 41 |
else if ($simple_list->display->display_format == SIMPLELIST_FORMAT_FULL) {
|
| 42 |
if (isset($node->teaser) && isset($node->body)) {
|
| 43 |
$items[] = node_view($node, FALSE, FALSE, FALSE);
|
| 44 |
}
|
| 45 |
else {
|
| 46 |
$items[] = theme('node', $node, FALSE, FALSE);
|
| 47 |
}
|
| 48 |
}
|
| 49 |
}
|
| 50 |
$result_nodes = theme('item_list', $items);
|
| 51 |
if ($simple_list->display->display_pager == 1) {
|
| 52 |
$result_nodes .= theme('pager', array(), $simple_list->display->display_count);
|
| 53 |
}
|
| 54 |
if ($simple_list->display->display_more_path != '') {
|
| 55 |
$result_nodes .= l('More', $simple_list->display->display_more_path);
|
| 56 |
}
|
| 57 |
return $result_nodes;
|
| 58 |
}
|
| 59 |
|
| 60 |
/**
|
| 61 |
* Displays the form elements needed to configure the SimpleListDisplay.
|
| 62 |
*
|
| 63 |
* @param unknown_type $simplelist
|
| 64 |
* @param unknown_type $format
|
| 65 |
* @return unknown
|
| 66 |
*/
|
| 67 |
public static function get_display_form($simplelist, $format='block') {
|
| 68 |
$form = array();
|
| 69 |
if ($format == 'block') {
|
| 70 |
$form['block_display_title'] = array(
|
| 71 |
'#type' => 'textfield',
|
| 72 |
'#title' => t('Block Title'),
|
| 73 |
'#default_value' => $simplelist->displays['block']->display_title,
|
| 74 |
'#size' => 80,
|
| 75 |
'#maxlength' => 255,
|
| 76 |
'#weight' => -5,
|
| 77 |
);
|
| 78 |
|
| 79 |
$form['block_display_count'] = array(
|
| 80 |
'#type' => 'textfield',
|
| 81 |
'#title' => t('Block Item Count'),
|
| 82 |
'#default_value' => $simplelist->displays['block']->display_count,
|
| 83 |
'#size' => 6,
|
| 84 |
'#maxlength' => 3,
|
| 85 |
'#weight' => -3,
|
| 86 |
);
|
| 87 |
|
| 88 |
$form['block_display_more'] = array(
|
| 89 |
'#type' => 'checkbox',
|
| 90 |
'#title' => t('Display \'More\' link - requires page view.'),
|
| 91 |
'#default_value' => $simplelist->displays['block']->display_more,
|
| 92 |
'#weight' => -1,
|
| 93 |
);
|
| 94 |
|
| 95 |
$form['block_display_format'] = array(
|
| 96 |
'#type' => 'select',
|
| 97 |
'#title' => t('Node Format'),
|
| 98 |
'#default_value' => $simplelist->displays['block']->display_format,
|
| 99 |
'#options' => array(
|
| 100 |
SIMPLELIST_FORMAT_TEASER => t('As Teaser'),
|
| 101 |
SIMPLELIST_FORMAT_FULL => t('As Full Node'),
|
| 102 |
SIMPLELIST_FORMAT_THEME => t('As Themed'),
|
| 103 |
SIMPLELIST_FORMAT_TITLE_LINK => t('As Titles, linking to node'),
|
| 104 |
),
|
| 105 |
'#multiple' => FALSE,
|
| 106 |
'#required' => TRUE,
|
| 107 |
'#description' => t('Choose how to display the nodes. If you use \'As Themed\', you should define a theme_simplelist__$name($node, $simplelist) function, where $name is the name of this simplelist.'),
|
| 108 |
'#weight' => 1,
|
| 109 |
);
|
| 110 |
|
| 111 |
$form['block_display_path'] = array(
|
| 112 |
'#type' => 'hidden',
|
| 113 |
'#title' => t('Argument Path'),
|
| 114 |
'#default_value' => $simplelist->displays['block']->display_path,
|
| 115 |
'#size' => 80,
|
| 116 |
'#maxlength' => 255,
|
| 117 |
'#weight' => 3,
|
| 118 |
);
|
| 119 |
}
|
| 120 |
else if ($format == 'page') {
|
| 121 |
$form['page_display_title'] = array(
|
| 122 |
'#type' => 'textfield',
|
| 123 |
'#title' => t('Page Title'),
|
| 124 |
'#default_value' => $simplelist->displays['page']->display_title,
|
| 125 |
'#size' => 80,
|
| 126 |
'#maxlength' => 255,
|
| 127 |
'#weight' => -7,
|
| 128 |
);
|
| 129 |
|
| 130 |
$form['page_display_count'] = array(
|
| 131 |
'#type' => 'textfield',
|
| 132 |
'#title' => t('Page Item Count'),
|
| 133 |
'#default_value' => $simplelist->displays['page']->display_count,
|
| 134 |
'#size' => 6,
|
| 135 |
'#maxlength' => 3,
|
| 136 |
'#weight' => -5,
|
| 137 |
);
|
| 138 |
|
| 139 |
$form['page_display_pager'] = array(
|
| 140 |
'#type' => 'checkbox',
|
| 141 |
'#title' => t('Display pager at bottom of page?'),
|
| 142 |
'#default_value' => $simplelist->displays['page']->display_pager,
|
| 143 |
'#weight' => -3,
|
| 144 |
);
|
| 145 |
|
| 146 |
$form['page_display_format'] = array(
|
| 147 |
'#type' => 'select',
|
| 148 |
'#title' => t('Node Format'),
|
| 149 |
'#default_value' => $simplelist->displays['page']->display_format,
|
| 150 |
'#options' => array(
|
| 151 |
SIMPLELIST_FORMAT_TEASER => t('As Teaser'),
|
| 152 |
SIMPLELIST_FORMAT_FULL => t('As Full Node'),
|
| 153 |
SIMPLELIST_FORMAT_THEME => t('As Themed'),
|
| 154 |
SIMPLELIST_FORMAT_TITLE_LINK => t('As Titles, linking to node'),
|
| 155 |
),
|
| 156 |
'#multiple' => FALSE,
|
| 157 |
'#required' => TRUE,
|
| 158 |
'#description' => t('Choose how to display the nodes. If you use \'As Themed\', you should define a theme_simplelist__$name($node, $simplelist) function, where $name is the name of this simplelist.'),
|
| 159 |
'#weight' => -1,
|
| 160 |
);
|
| 161 |
|
| 162 |
$form['page_display_path'] = array(
|
| 163 |
'#type' => 'textfield',
|
| 164 |
'#title' => t('Page Path'),
|
| 165 |
'#default_value' => $simplelist->displays['page']->display_path,
|
| 166 |
'#size' => 80,
|
| 167 |
'#maxlength' => 255,
|
| 168 |
'#weight' => 1,
|
| 169 |
'#description' => t('Enter the path to display this page at. For arguments you can include %tid to include the termid, or %node_type to include the node type. If these are included, they\'ll override whatever term or type were assigned as a parameter. I don\'t recommend using a parameter for the first part of the path.'),
|
| 170 |
);
|
| 171 |
}
|
| 172 |
return $form;
|
| 173 |
}
|
| 174 |
|
| 175 |
/**
|
| 176 |
* Clears out the existing data.
|
| 177 |
*
|
| 178 |
* @param unknown_type $slid
|
| 179 |
* @param unknown_type $form_id
|
| 180 |
* @param unknown_type $form_state
|
| 181 |
* @param unknown_type $format
|
| 182 |
*/
|
| 183 |
public static function clear_existing_settings($slid, $form_id='', &$form_state=NULL, $format='block') {
|
| 184 |
// There's no existing settings that won't be overritten anyway.
|
| 185 |
|
| 186 |
}
|
| 187 |
}
|
| 188 |
?>
|