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?

4
  • Try BaseFieldDefinition::create('text') or BaseFieldDefinition::create('text_long') – No Sssweat May 31 '17 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 '17 at 2:46
  • 1
    create('string_long') gets you a LONGTEXT type field without an extra _format column. Perhaps that would work for you? – user72086 May 31 '17 at 3:32
  • @Lisa That's what I needed, thanks. If you add that as an answer I'll mark it as the accepted answer. – Jaypan May 31 '17 at 3:34
1

You can use BaseFieldDefinition::create('string_long') to get a LONGTEXT type field without the extra__format column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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