checkboxes drupal

Me resultó un poco difícil poder crear una tabla que liste nodos con un campo de checkboxes para seleccionar a un grupo de estos por la poca información que encontré en Internet. Pero para quién le pueda servir publico como poder hacerlo.

function GLRPolls_settings_form() {
$form = null;
$r = db_query(“SELECT n.nid, n.title, n.status, n.created, ctp.field_poll_cat_seccion_tid as idcat, td.name
FROM node n, content_type_poll_cat ctp, term_data td
WHERE n.type =’poll_cat’ AND n.nid = ctp.nid AND ctp.field_poll_cat_seccion_tid = td.tid”);

while ($row = db_fetch_object($r)) {
$rows[] = $row;
}
$nids = array();
foreach ($rows as $v) {
$nids[$v->nid] = ”;
$form[‘title’][$v->nid] = array(‘#type’ => ‘markup’, ‘#value’ => $v->title);
$form[‘created’][$v->nid] = array(‘#type’ => ‘markup’, ‘#value’ => date(“d/m/Y”, $v->created));
$form[‘name’][$v->nid] = array(‘#type’ => ‘markup’, ‘#value’ => $v->name);
$form[‘idcat’][$v->nid] = array(‘#type’ => ‘markup’, ‘#value’ => $v->idcat);
}

$form[‘nids’] = array(
‘#type’ => ‘checkboxes’,
‘#options’ => $nids,
‘#default_value’ => variable_get(‘nids’, array()),
);

$form[‘submit’] = array(‘#type’ => ‘submit’, ‘#value’ => ‘Seleccionar’);
$form[‘header’] = array(
‘#type’ => ‘value’,
‘#value’ => array(
array(‘data’ => ‘nid’),
array(‘data’ => t(‘Titulo’)),
array(‘data’ => t(‘Creado’)),
array(‘data’ => t(‘Categoria’)),
array(‘data’ => t(‘IdCat’)),
)
);
return $form;
}

function GLRPolls_settings_form_submit($form_id, $form_values){
variable_set(‘nids’, $form_values[‘nids’]);
$featured = $form_values[‘nids’];
foreach($featured as $key => $value) {
if ($value) {
drupal_set_message(t($value));
}
}
}

function theme_GLRPolls_settings_form($form) {

foreach (element_children($form[‘title’]) as $key) {
$row = array();
$row[] = drupal_render($form[‘nids’][$key]);
$row[] = drupal_render($form[‘title’][$key]);
$row[] = drupal_render($form[‘created’][$key]);
$row[] = drupal_render($form[‘name’][$key]);
$row[] = drupal_render($form[‘idcat’][$key]);

$rows[] = $row;
}
$output = theme(‘table’, $form[‘header’][‘#value’], $rows);
$output .= drupal_render($form); // Process any other fields and display them
return $output;
}

function GLRPolls_menu($may_cache) {
$items = array();
if ($may_cache) {
$access = user_access(‘administer GLRPolls’);
$items[] = array(
‘path’ => ‘admin/settings/GLRPolls’,
‘title’ => t(‘GLRPolls’),
‘description’ => t(‘Configurando Polls.’),
‘callback’ => ‘GLRPolls_admin_list’,
‘access’ => $access,
);
}
return $items;
}

function GLRPolls_admin_list() {
$output = drupal_get_form(‘GLRPolls_settings_form’);
return $output;
}

Puntuación: 1.00 / Votos: 1