Problemas con TableSelect Drupal7
Hola a todos:
Estoy empezando a programar en Drupal 7 y tengo una duda que quizas alguno de ustedes me podria resolver.
Estoy haciendo un modulo que hace una consulta a la base de datos y me muestra en una tabla los resultados . Para ello utilizo tableselect para mostrar los resultados de la consulta y que se incluya en cada fila de resultados un checkbox pero no me muestra ningun resultado. El caso es que los valores de los resultados si que se recogen pero el problema esta al mostrarlo.
He probado ha hacerlo sin utilizar el table select y si que los muestra. El error está al hacer la llamada al tema , pero no consigo averiguar cual puede ser el problema.
Este es el codigo, y agradezco cualquier ayuda que me puedan ofrecer.
Muchas Gracias a todos y perdonen mi torpeza.
<?php
/**
*Implementando el hook_help
*/
function tableselect_help($path, $arg)
{
$output = '';
switch ($path)
{
case 'admin/help#grid_tableselect':
$output= '' . t("Tabla de pruebas") . '';
break;
}
return $output;
}
/**
*Implementando el hook_menu
*/
function tableselect_menu()
{
$items['listado/listado-tableselect'] = array(
'title' => 'Listado Table Select',
'page callback' => 'tableselect_listado_form',
'access callback' => TRUE,
);
return $items;
}
function tableselect_listado_form() {
$form = array();
$header = array(
'nid' => array('data' => t('Nid'), 'field' => 'n.nid'),
'vid' => array('data' => t('vid'), 'field' => 'n.vid'),
'type' => array('data' => t('Type'), 'field' => 'n.type'),
'language' => array('data' => t('Lenguage'), 'field' => 'n.language'),
'title' => array('data' => t('Title'), 'field' => 'n.title'),
'status' => array('data' => t('Status'), 'field' => 'n.status'),
'created' => array('data' => t('Creado'), 'field' => 'n.created', 'sort' => 'desc')
);
//Get the node data.
$query = db_select('node','n')->extend('PagerDefault');
$query-> fields('n',array('nid','vid','type','language','title','status','created')) ;
$query-> range(0,15) ;
$query-> orderByHeader($header) ;
$query = $query->extend('PagerDefault');
//->execute();
//->fetchCol();
$result = $query->execute();
$options=array ();
foreach($result as $row)// = db_fetch_array($rows)) // we loop through the results
{
// $checkboxes[$row->nid] = ''; // a blank value is given so that the checkboxes have no title and are just rendered as a blank checkbox
// $options[$row->nid] = array('#value' => $row->nid);
// $options[$row->vid] = array ("#value" => $row->vid);
// $options[$row->type] = array ("#value" => $row->type);
// $options[$row->language] = array ("#value" => $row->language);
// $options[$row->title] = array ( "#value" => $row->title);
// $options[$row->status] = array ( "#value" => $row->status);
// $options[$row->created] = array ( "#value" => $row->created);
// $options[]= array (
// 'nid' => $row->nid,
// 'vid' => $row->vid,
// 'type' => $row->type,
// 'language' => $row->language,
// 'title' => $row->title,
// 'status' => $row->status,
// 'created' => $row->created,
// );
$options[$row->nid] = array(
'nid' => array(
'data' => array(
'#type' => 'link',
'#title' => $row->nid,
'#href' => 'node/' . $row->nid,
//'#options' => $l_options,
//'#suffix' => ' ' . theme('mark', array('type' => node_mark($row->nid, $row->changed))),
),
),
'vid' => $row->vid,
'type' => check_plain(node_type_get_name($row)),
'language' => $row->language,
//'author' => theme('username', array('account' => $node)),
'title' => $row->title,
'status' => $row->status ? t('published') : t('not published'),
'created' => format_date($row->created, 'short'),
);
};
if (!empty($options)) {
$form['nodes'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No Existen Resultados que mostrar'),
'#multiple' => TRUE,
//'#default_value' => $options,
);
$form['pager'] = array('#value' => theme('pager'));
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
}
// $output=theme('table', array ('header'=>$header, 'rows'=>$options));
// return $output;
return $form;
}
- Inicie sesión o regístrese para enviar comentarios

tu item de menú puede ser el probema
Hola
Acabo de leer (muy por encima tu código) y me parece que estás devolviendo un array que no es tomado por drupal como la definición de un form en regla.
prueba este código en tu hook_menu():
<?php
function tableselect_menu(){
$items['listado/listado-tableselect'] = array(
'title' => 'Listado Table Select',
'page callback' => 'drupal_get_form',
'page arguments' => array('tableselect_listado_form'),
'access callback' => TRUE,
);
return $items;
}
?>
Si observas con cuidado, el callback pide a drupal que entienda el array de respuesta como formulario y pasó tu función a la posición de argumento. drupal_get_form va a llamar a tu función para que le entregue el array de definición y va a llamar todo lo que necesita para gestionar y mostrar dicho form. Si tu lo llamas desde tu código, directamente, sin invocar, otros métodos necesarios, vas a recibir mensajes de error que te van a quitar el sueño por mucho tiempo.
Tambien se puede conseguir el form por el camino que elegiste pero "tiene mucha magia" para mostrar en este lugar de modo que se entienda.
Ah!, otro detalle, tu menú está quedando expuesto para que cualquiera haga click sobre el porque el default del parametro 'type' es MENU_NORMAL_ITEM y, es posible que desees restringir un poco el acceso o sólo llamarlo desde código, consulta un poco sobre el uso de hook_perm() para restringir su accesibilidad y otras parametrizaciones de type para definir cómo y dónde se muestra.