0

I need to update a default value of column

/**
  * {@inheritdoc}
  */
public static function schema(FieldStorageDefinitionInterface $field_definition) {
  return [
    'columns' => [
      'status' => [
        'description' => 'Whether reactions are allowed on this entity: 0 = no, 1 = closed (read only), 2 = open (read/write).',
        'type' => 'int',
        'default' => 0, // <-- HERE
      ],
    ],
    'indexes' => [],
    'foreign keys' => [],
  ];
}

When I changed from 0 to 2 I get error on status report page about "field definitions mismatch"

There are a lot of questions about adding and removing columns. Here for example, but I don't understand how to update schema PROGRAMMATICALLY without adding or removing column

4
  • This is a better example, you need only to replace setRequired() with setDefaultValue().
    – 4uk4
    Commented Oct 31, 2023 at 13:01
  • What "entity type" should I use for FieldItemBase?
    – Vanish
    Commented Oct 31, 2023 at 18:28
  • \Drupal::service('entity_field.manager')->getFieldMapByFieldType($field_type)
    – 4uk4
    Commented Oct 31, 2023 at 18:54
  • I found update field code here gist.github.com/JPustkuchen/ce53d40303a51ca5f17ce7f48c363b9b
    – Vanish
    Commented Nov 2, 2023 at 9:12

0

Your Answer

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

Browse other questions tagged or ask your own question.