- Issue created by @joachim
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.
Understood. But with β¨ Do not require a 'title' field Needs work and its duplicates over the years, this seems the same issue.
- πΊπΈUnited States TolstoyDotCom L.A.
It seems to me that everything should have a title, even in the case of a "Person" object. The title could be random, or constructed from something else, but you should always be able to count on an existing entity having a title of some kind just as you can count on it having an ID.
Also, I don't think handling this at the form level would be a good idea since someone might hide the title and then have custom code or a contrib module that provides the title. Preventing them from hiding the title would cause problems for them. If you let them do it but instead show a warning that would annoy people who know what they're doing and confuse others.
I suggest changing SqlContentEntityStorage::mapToStorageRecord to throw an exception if a field is required but empty. It already throws an exception in one case
throw new EntityStorageException("Table mapping contains invalid field $field_name.");
so adding a check in the same area doesn't seem out of place. You're going to get an exception in any case, it might as well give the user a clue what the problem is. Hi,
Already the issue is noticed and we have patch in the ticket https://www.drupal.org/project/drupal/issues/2358537 β¨ Do not require a 'title' field Needs work . Rerolled the patch also for the latest version in that ticket.So instead duplicate we can close this ticket.
- π·π΄Romania amateescu
The DB field in {node_field_data} does not have ALLOW NULL, but for {block_content_field_data} it does.
That's because the node entity schema explicitly marks the
title
field as NOT NULL in\Drupal\node\NodeStorageSchema::getSharedTableFieldSchema()
.Closing as a duplicate of β¨ Do not require a 'title' field Needs work .