I am struggling to get a working custom implementation of a cck_phone field from the cck_phone module. I have included my partially working code at the bottom.

What seems to be not working is that the function cck_phone_phone_number_process expects to be able to retrieve information about the widget with

$instance = field_widget_instance($element, $form_state); $settings = $instance['settings'];

However in my implementation, field_widget_instance($element, $form_state) returns NULL, resulting in both $instance and $settings being NULL and problems further on in the cck_phone_phone_number_process function.

What does work is that the code below does render a properly populated country code dropdown and phone number entry textfield.

My code to create the custom cck_phone field:

$form_section['phone']['field_phone_home'] = array(
    '#type' => 'phone_number',
    '#field_parents' => array(
    '#field_name' => 'field_phone_home',
    '#language' => 'und',
    '#delta' => 0,
  • cck_phone does define a form element (good) but uses field functions (bad), have you tried to file an issue on drupal.org? by custom implementation I assume you mean a custom form which is not an entity form with fields on it? – hkoosha Oct 6 '14 at 18:08
  • I have filed an issue on Drupal.org. I have received no help from that issue. I guess I don't fully understand the second part of your comment - "by custom implementation I assume you mean a custom form which is not an entity form with fields on it?" By "custom form" I mean it is a form built in code using various fields from various parts of user profiles, not a built in form to a module, or part of webform or something like that. – DrCord Oct 6 '14 at 21:09
  • yeah that's what I meant, the form is not an entity form (even a custom entity type) -> thus field hooks wont be called -> probably you have no luck and should to patch the module! – hkoosha Oct 6 '14 at 21:13
  • The phone field works fine elsewhere, rendering an extension field, etc. I find it hard to believe that it works elsewhere perfect, but cannot work here...can you support your supposition with evidence? – DrCord Oct 7 '14 at 13:12
  • Can you give me an example of it working elsewhere, somewhere which is not an entity creation/editing form? maybe I can figure it out what's wrong – hkoosha Oct 7 '14 at 15:57

I was unable to find an exact answer to this question, but I was able to find a work around to get the extensions to load.

using form_alter, after the field is partially built in a form function

//set value for office extension
    $form_state['storage']['$profiles']['personal_information']->field_phone_office[LANGUAGE_NONE][0]['extension'] != NULL
    $field_phone_office_ext_value = $form_state['storage']['$profiles']['personal_information']->field_phone_office[LANGUAGE_NONE][0]['extension'];
    $field_phone_office_ext_value = '';

  $form['user-information']['user-information-fieldset']['profile']['phone']['field_phone_office']['extension'] = array(
    '#type' => 'textfield',
    '#title' => t('Ext.'),
    '#default_value' => $field_phone_office_ext_value,
    '#value' => $field_phone_office_ext_value,
    '#size' => 10,
    '#maxlength' => 10,
    '#weight' => 2,
    '#attributes' => array(
      'class' => array(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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