Hello,
I want to show a Select Field where the content author can select a user with a specific Role (In my case role id = 4)
I'm trying to do this with a Widget. My select field works and also my database query but i don't know how to put the received uid and username as options into the select field as id and value.
It should looks like:
<select class="form-select">
<option value="_none">None</option>
<option value="0">Anonymous</option>
<option value="1">admin</option>
<option value="22">Bob</option>
<option value="45">Marry</option>
</select>
This is my Code:
<?php
/**
* Implements hook_field_widget_info().
*/
function selectuserbyrole_field_widget_info(){
return array(
'selectuserbyrole_selectfield' => array(
'label' => t('Select user by Role'),
'field types' => array('entityreference',),
),
);
}
/**
* Implements hook_field_widget_form().
*/
function selectuserbyrole_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element){
$element = array(
'#type' => 'select',
'#default_value' => '0',
'#value_callback' => 'selectuserbyrole_field_widget_value',
);
return $element;
}
function selectuserbyrole_field_widget_value($element){
$result = db_query("SELECT u.uid, u.name, ur.uid, ur.rid