Both the Examples module and the Drupal Console generate:entity:content both have code like this:

$fields['first_name'] = BaseFieldDefinition::create('string')
  ->setLabel(t('First Name'))
  ->setDescription(t('The first name of the Contact entity.'))
    'default_value' => '',
    'max_length' => 255,
    'text_processing' => 0,

I was thinking that if I provided 'default_value' => 'Fred' in place of 'default_value' => '' that I might affect the default value of the field. I would expect to have seen Fred when creating an entity of this type, and I might have expected to see Fred as the default value in the entity's table definition, but it's not there.

I'm learning D8 and so have two parts to this question really, the first is just how to provide a default value, the second is if this default_value key isn't it, what is it for?

1 Answer 1


The code is outdated, you should create a patch to fix it.

There is a new separate method for the default value, setDefaultValue().

  • Thanks, I've had a go at supplying a patch to examples. Never done it before so I expect I've done something terribly wrong in the process so am bracing myself for correction! Jun 24, 2015 at 9:07
  • Thanks, artfulrobot. You might also ping the console people, too.
    – paul-m
    Aug 8, 2015 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.