Created
February 10, 2014 19:33
-
-
Save bronius/8922601 to your computer and use it in GitHub Desktop.
Attempt to nest Drupal 7 FAPI element type tableselect (Note: It doesn't work!)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file megaselect.module | |
* TODO: Enter file description here. | |
*/ | |
/** | |
* Implements hook_menu(). | |
*/ | |
function megaselect_menu() { | |
$items['megaselect'] = array( | |
'title' => 'Megaselect', | |
'page callback' => 'drupal_get_form', | |
'page arguments' => array('megaselect_megaform'), | |
'access arguments' => array('access content'), | |
'type' => MENU_CALLBACK, | |
); | |
return $items; | |
} | |
function megaselect_megaform($form, $form_state) | |
{ | |
$users = array | |
( | |
array('uid' => 1, 'first_name' => 'Indy', 'last_name' => 'Jones' | |
, 'nicknames' => array('indy', 'andy', 'pandy')), | |
array('uid' => 2, 'first_name' => 'Darth', 'last_name' => 'Vader' | |
, 'nicknames' => array('durth', 'dearth', 'dark')), | |
array('uid' => 3, 'first_name' => 'Super', 'last_name' => 'Man' | |
, 'nicknames' => array('supper', 'dessert', 'stormy', 'catcherman')), | |
); | |
$header = array | |
( | |
'first_name' => t('First Name'), | |
'last_name' => t('Last Name'), | |
'nick_name' => t('Nick Name'), | |
); | |
$options = array(); | |
foreach($users as $user) | |
{ | |
$rowid = $user['uid']; | |
$inneroptions = drupal_map_assoc($user['nicknames']); | |
$innerheader = array('Choose a Nickname'); | |
$innerform = array ( | |
'#type' => 'tableselect', | |
'#header' => $innerheader, | |
'#options' => $inneroptions, | |
'#multiple' => FALSE, | |
'#title' => 'Nickname', | |
'#title_display' => 'invisible', | |
'#default_value' => '', | |
'#id' => 'nickname_row' . $rowid . '', | |
'#name' => 'nickname[row' . $rowid . ']', | |
'#empty' => t('No nicknames to choose from'), | |
); | |
// dpm($inneroptions, 'inner options'); | |
$options[$rowid] =array | |
( | |
'first_name' => $user['first_name'], | |
'last_name' => $user['last_name'], | |
'nick_name' => array('data' => array( | |
$innerform, | |
), | |
) | |
); | |
} | |
$form['table'] = array | |
( | |
'#type' => 'tableselect', | |
'#header' => $header, | |
'#options' => $options, | |
'#empty' => t('No users found'), | |
); | |
$form['nickname'] = array( | |
'#type' => 'value', | |
); | |
$form['submit'] = array | |
( | |
'#type' => 'submit', | |
'#value' => t('Submit'), | |
); | |
dpm($form); | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work (yet?). The example whipped up is based on the clever hack on how to stuff more FAPI form fields into a tableselect than are allowed out of the box (none). I am not sure it can be done... but I'd love to be proven wrong!