0

I'm trying to use the technique outlined in this blog post:

https://www.hexblot.com/blog/drupal-tableselect-fields

to add a select box to a tableselect, but there are a couple of issues:

  • The default value is not being respected (I've tried using #value and #default_value)
  • The roles element is empty on submit

Any idea what I'm missing? Here's my code:

foreach ($query as $row) {
  $member = user_load($row->etid);
  $roles = og_get_user_roles('node', $org->nid, $member->uid, FALSE);
  $role = reset($roles);
  $role = $role ? $role : 'campaigner';
  $rows[$member->uid] = [ 
    'mail' => $member->mail,
    'current_role' => $role,
    'role' => [ 
      'data' => [ 
        '#type' => 'select',
        '#name' => 'role[' . $member->uid . ']',
        '#options' => [ 
          'campaigner' => 'Campaigner',
          'administrator' => 'Administrator',
        ],
        '#default_value' => $role,
      ],
    ],
  ];
} 

$form['team_heading']['team'] = [
  '#type' => 'tableselect',
  '#header' => [
    'mail' => t('Email'),
    'current_role' => t('Current Role'),
    'role' => t('V2 Role')
  ],
  '#options' => $rows,
  '#js_select' => FALSE,
  '#default_value' => drupal_map_assoc(array_keys($rows)),
];

$form['role'] = ['#type' => 'value'];

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.