2

I have created a custom entity and i'm using CCK fields. Each bundle has it's own fields. For example:

function MYMODULE_install() {
  // Check if our field is not already created.
  if (!field_info_field('field_myField')) {
    $field = array(
        'field_name' => 'date_field',
        'type' => 'list_text',
    );
    field_create_field($field);
}

//Enable is executed only once.

function bundle_callback_enable() {

  // Create the instance on the bundle.
  $instance = array(
    'field_name' => 'date_field',
    'entity_type' => 'payment_method',
    'label' => 'Expiration Date',
    'bundle' => 'card',
    'required' => TRUE,
    'settings' => array();

  field_create_instance($instance);
}

My bundles are created from individual modules, so in each install file i am creating the respective fields.

Yesterday i tried to add validation callback functions in those fields and i saw something weird inside form array. Fields with type="text" had the path:

$form[field_name]['und'][0][value] // expectable

but fields with type='list_text' had only the path:

$form[field_name]['und'] // unexpectable

I couldn't find any solution and i've solved it with this way:

function &get_cck_path_value( $field_name, &$form_path) {

  $field = null
  if ( isset( $form_path[$field_name][LANGUAGE_NONE] )) {
     $field = &$form_path[$field_name][LANGUAGE_NONE]
  }
  elseif(isset($form_path[$field_name][LANGUAGE_NONE][0])) {
    $field =  &$form_path[$field_name][LANGUAGE_NONE][0]['value'];
  }
  return $field;
}

I don't like this approach. Is too hucky. Can you tell me if that is a cck feature or bug? I can't understand when it decides where to put the values( All the process is fulfilled through the "field_attach_form( ... )" )?

Have you faced any problem like this?

Thanks.

Your Answer

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

Browse other questions tagged or ask your own question.