Hiding the node title makes node form submission crash

Created on 30 October 2023, 10 months ago
Updated 31 October 2023, 10 months ago

Problem/Motivation

To reproduce:

1. Go to form display management for a node type
2. Hide the title field
3. Try to save a node of this type

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null: INSERT INTO "node_field_data" ("nid", "vid", "type", "langcode", "status", "uid", "title", "created", "changed", "promote", "sticky", "default_langcode", "revision_translation_affected") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12); Array ( [:db_insert_placeholder_0] => 2 [:db_insert_placeholder_1] => 2 [:db_insert_placeholder_2] => page [:db_insert_placeholder_3] => en [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => 1698684363 [:db_insert_placeholder_8] => 1698684366 [:db_insert_placeholder_9] => 0 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => 1 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @joachim
  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    Is this the same as ✨ Do not require a 'title' field Needs work ?

  • πŸ‡¬πŸ‡§United Kingdom joachim

    What I don't understand is how the same procedue on the Custom Block entity type does NOT crash, when both fields look very similar in their definition:

        $fields['title'] = BaseFieldDefinition::create('string')
          ->setLabel(t('Title'))
          ->setRequired(TRUE)
          ->setTranslatable(TRUE)
          ->setRevisionable(TRUE)
          ->setSetting('max_length', 255)
          ->setDisplayOptions('view', [
            'label' => 'hidden',
            'type' => 'string',
            'weight' => -5,
          ])
          ->setDisplayOptions('form', [
            'type' => 'string_textfield',
            'weight' => -5,
          ])
          ->setDisplayConfigurable('form', TRUE);
    
        $fields['info'] = BaseFieldDefinition::create('string')
          ->setLabel(t('Block description'))
          ->setDescription(t('A brief description of your block.'))
          ->setRevisionable(TRUE)
          ->setTranslatable(TRUE)
          ->setRequired(TRUE)
          ->setDisplayOptions('form', [
            'type' => 'string_textfield',
            'weight' => -5,
          ])
          ->setDisplayConfigurable('form', TRUE)
          ->addConstraint('UniqueField', []);
    

    What is different?

    The DB field in {node_field_data} does not have ALLOW NULL, but for {block_content_field_data} it does.

  • πŸ‡ΊπŸ‡ΈUnited States cilefen

    Understood. But with ✨ Do not require a 'title' field Needs work and its duplicates over the years, this seems the same issue.

Production build 0.71.5 2024