i have a list (text) field with allowed values of:

Small Office|Small Office
Large Office|Large Office
Light Industrial|Light Industrial

i have my default php set as:

return array(0=>array('Small Office'));

when i add a new node my field is not set to default.

Comments

brianbrarian’s picture

PHP for default value isn't working for me, either.

In my case, I'm trying to set the default for a field in a node type that is also in the user entity. The allowed values are populated with PHP code (and that works), and now I'm trying to get the value from the field in the current user's profile to be the default for the field's instance in the node.

I've tried several variations on this code (without the php tags):

<?php
  global $user;
  $user_data = user_load($user->uid);
  $myfield_default = $user_data->field_myfield['und']['0']['value'];
  return array (
    0 => array($myfield_default),
  );
?>

I've also tested by replacing the $myfield_default variable in the array with a hardcoded key value that is included in the array returned by the allowed-values PHP code, but that doesn't get set as the default either.