Search code examples
phpdrupaldrupal-fapi

Drupal Form-API: #field_prefix doesn't work on textfield


I'm trying to implement #field_prefix on a text field so I can add some extra UI to my form.

I have a module where I'm doing other overrides like this, with a function that basically looks like this:

function modulename_form_alter(&$form, $form_state, $form_id){
    if ($form_id == "contenttype_node_form"){
        $form['field_contenttype_fieldname'][0]['#prefix'] = 'prefix';  //this line works           
        $form['field_contenttype_fieldname'][0]['#field_prefix'] = 'field_prefix';  //this line doesn't work
    }

Here's the docs, seems pretty straight forward: http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/6#field_prefix

I've renamed my theme to effectively disable it - should prove I don't have any other overrides hanging around that would conflict.

What am I missing?

Update: Ended up overriding theme_form_element to insert my prefix manually when the #field_name meets the right condition. Feels hacky, but text_textfield simply doesn't support #field_prefix.


Solution

  • My guess is that as a CCK field field_contenttype_fieldname isn't actually a textfield, but a custom FormAPI field CCK provides that's like a textfield, and as such it doesn't consume the field_prefix attribute.

    Try print_r()ing that field out of the $form and see what its #type is.