Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
brianbrarian CreditAttribution: brianbrarian commentedPHP 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):
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.