[development] creating new cck field

Ámon Tamás amont at 5net.hu
Fri Sep 19 18:59:04 UTC 2008


Hello,

I like to make a new cck field type, but I am very confused with it. I 
do not get back the field in the form. I try to see the example_field 
and simple_field and optionwidgets module but do not find the solution.

I like to make a number_integer field with an autocomplete feature. This 
is my code now. What is missing? I use drupal 6.

Thanks for help!

function atletafield_atleta_process($element, $edit, &$form_state, $form) {
   $field_name = $element['#field_name'];
   $field = $form['#field_info'][$field_name];
   $field_key  = $element['#columns'][0];
   $element[$field_key] = array(
     '#type' => 'textfield',
     '#maxlength' => 60,
     '#title' => $element['#title'],
     '#description' => $element['#description'],
     '#required' => $field['required'],
     '#autocomplete_path' => 'atleta/autocomplete_athlete',
     '#default_value' => isset($element['#value'][$field_key]) ? 
$element['#value'][$field_key] : NULL,
     '#attributes' => array('class' => 'atletafield')
   );
   return $element;
}

function atletafield_elements() {
     $elements['atletafield_atleta'] = array(
       '#input' => TRUE,
       '#columns' => array('value'), '#delta' => 0,
       '#process' => array('atletafield_atleta_process'),
       );
       return $elements;
}
/* I think this part is good */
function atletafield_widget_info() {
   return array(
     'atletafield_atleta' => array(
       'label' => t('Atleta selector'),
       'field types' => array('number_integer'),
       'multiple values' => CONTENT_HANDLE_CORE,
       'callbacks' => array(
         'default value' => CONTENT_CALLBACK_DEFAULT,
         ),
     ));
}

function atletafield_theme() {
return array(
     'atletafield_atleta' => array(
       'arguments' => array('element' => NULL),
     ),
   );
}

function theme_atletafield_atleta($element) {
   return $element['#children'];
}
function atletafield_content_is_empty($item, $field) {
   if (empty($item['value'])) {
     return TRUE;
   }
   return FALSE;
}
function atletafield_widget(&$form, &$form_state, $field, $items, $delta 
= 0) {
   $element = array(
     '#type' => $field['widget']['type'],
     '#default_value' => !empty($items) ? $items : array(),
   );
   return $element;
}

Ámon Tamás
Sitefejlesztő és programozó
-- 
5NET Informatikai Kft.
1062 Budapest, Aradi utca 38. A 3/11
telefon: (1) 461-0205  |  fax: (1) 461-0206
e-mail: amont at 5net.hu  |  web: http://www.5net.hu


More information about the development mailing list