0

In a content entity definition, I've got the following:

public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  $fields = parent::baseFieldDefinitions($entity_type);

  $fields['frames'] = BaseFieldDefinition::create('string')
    ->setLabel(t('Frames'))
  ->setDescription('A serialized representation of the given frames');

  return $fields;
}

This is creating the column type in the database as varchar, with a maxlength of 255. I need the column to be type text, as the length will be unknown, and often more than 255. Does anybody know how to create a BaseFieldDefinition that becomes type 'text' in the database when the content entity is enabled?

2
  • Try BaseFieldDefinition::create('text') or BaseFieldDefinition::create('text_long')
    – No Sssweat
    May 31, 2017 at 2:33
  • I tried that, and it only adds a _format column to the table, but leaves the original column as varchar
    – Jaypan
    May 31, 2017 at 2:46

1 Answer 1

1

BaseFieldDefinition::create('string_long') creates a LONGTEXT database column without the extra _format column.

Your Answer

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

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