won't work with Select CCK fields, returns nothing.

Comments

Taz’s picture

Status: Active » Needs review

I followed it through and found that it's more of an issue with CCK or Token. The select field in the node array has a ['key'] rather than [0], which can be seen in the below hack. This either needs to be addressed in token so it can work out if it's a select field ($node->$field['field_type']) is both text for drop down boxes as well as normal input fields)

Below is the temporary fix that works without being site or field_name specific. So far hasn't broken anything else.

function content_token_values($type, $object = NULL) {
  $tokens = array();
  if ($type == 'node') {
    $node = $object;
    foreach (content_fields() as $field) {
      $items = $node->$field['field_name'];

// This has been added in by Agileware to allow SELECT boxes to actually work with auto_nodetitle
// If a 'key' value in the array is not found (in select node arrays) then use the normal way
// content_format was eating the data inside $items['key'], no $items['0'] exists.

      if($items['key']){
        $tokens[''. $field['field_name'] .''] = $items['key'];
      }
      else{
        $tokens[''. $field['field_name'] .''] = content_format($field['field_name'], $items[0]);
      }

    }
    print_r($tokens);
  }
  return $tokens;
}
fago’s picture

Project: Automatic Nodetitles » Token
Version: 5.x-1.x-dev » 5.x-1.4
Status: Needs review » Needs work

recategorized to token module.
please have a look at how to create a patch

eaton’s picture

Status: Needs work » Closed (duplicate)