Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I used hook_field_widget_info() and hook_field_widget_form() to create a new widget for the user reference module. The problem is when I select a value in content edit form using my widget, selected value is not shown in node display page. Also when I go back to the edit form, my selected value is not the default value(is not saved).

Does it need anything else to work properly?

function mymodule_field_widget_info() {
    return array(
       'custom_user_widget' => array(
            'label' => 'Custom user widget',
            'field types' => array('user_reference'),
            'behaviors' => array(
                'multiple values' => FIELD_BEHAVIOR_DEFAULT,
                'default value' => FIELD_BEHAVIOR_DEFAULT,
function mymodule_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
    if ($instance['widget']['type'] == 'custom_user_widget') {
        $element['uid'] = array(
            '#type' => 'select',
            '#options' => array(1=>'a', 2=>'b', 3=>'c'),
            '#title' => t('Username')
        return $element;

share|improve this question

You need to implement the "view hook":

* Implements hook_field_formatter_view().
function mymodule_field_widget_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
    $element = array();

    switch ($display['type']) {
    case 'custom_user_widget':
    $element[] = 'add here what you want to show';
    return $element;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.