Problem/Motivation
When creating custom content types, the "Title" field is manditory. This leads to akward work-arounds for content types that do not need a 'title' / 'short text' field. One example would be modeling people:
person { first_name, last_name } // no title necessary
Please provide a means by which we can create new content types through the UI without a mandatory title field (i.e. plain text field).
Some workarounds for the node title requirement, which indicate a longstanding, underlying usability issue, include:
- Module Monday: Exclude Node Title
- Title
- Automatic Nodetitles (D7)
- WikiTools Auto Node Title (D6)
- Automatic Entity Label (D7)
- Title Field for Manage Display
- Smart Title
- Show title
Proposed resolution
Workaround - hide the title field on the form: admin/structure/types/manage/custom_content_type/form-display
Setting the title field to hidden will let you create nodes without the title.
| Comment | File | Size | Author |
|---|---|---|---|
| #70 | title-require-after-patch.png | 77.05 KB | yasminorj |
| #65 | 2358537.patch | 1.92 KB | manibharathi ezhimalai ravi |
| #63 | 2358537-nr-bot.txt | 150 bytes | needs-review-queue-bot |
| #60 | new content.png | 41.33 KB | akhildev.cs |
| #60 | create_content.png | 64.94 KB | akhildev.cs |
Issue fork drupal-2358537
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
brylie commentedComment #2
brylie commentedComment #3
brylie commentedComment #4
benelori commentedYou can hide the title field on the form if you want:
admin/structure/types/manage/custom_content_type/form-display
Setting the title field to hidden will let you create nodes without the title.
Comment #5
brylie commentedThanks for the quick response benelori. I will make this change on custom content types going forward.
It still seems like it covers up the underlying assumption that 'all content types will have a title', which IMO is erroneous.
Comment #6
benelori commentedYes looks like it...when I first saw this issue, all the presentations on Entity API sprang into mind, where exactly that was said, but knowing that we can alter the node form BO, I decided to give it a shot.
Looking at the database, I think the 'all content types will have a title' statement is based on the fact that there is a title column in the node_field_data table.
Comment #7
berdirThis is about the node entity type, not the entity system.
Comment #8
brylie commentedThanks @benelori and @Berdir for the clarification that this is related to the node system. :)
Comment #9
ivarlaks commentedComment #10
dimitrov.adrian commentedWhen you hide the title field from field "Manage form display", and then try to add some node, you get unexpected error, and no node is added. So I think, this issue could be classified as a bug.
Comment #11
alex.barylski commented@dimitrov.adrian
It seems that when I hide the title and attempt to create a new entity record I receive this error:
The website encountered an unexpected error. Please try again later.
Looking into the logs I see this error as well:
Am I missing a step in D8 (8.0.2)???
This would be nice not to have to worry about :)
Comment #12
mcvjoyner commented@alex.barylski
Confirmed in Core 8.0.5
I created a custom content type, and hid the the 'title' field. Everything went fine, until I tried to submit the new node, obviously without the title.
Error:
Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null: INSERT INTO {node_field_data} (nid, vid, type, langcode, title, uid, status, created, changed, promote, sticky, revision_translation_affected, default_langcode, ds_switch) 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, :db_insert_placeholder_13); Array ( [:db_insert_placeholder_0] => 11 [:db_insert_placeholder_1] => 11 [:db_insert_placeholder_2] => testimonial [:db_insert_placeholder_3] => en [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 1 [:db_insert_placeholder_7] => 1456957777 [:db_insert_placeholder_8] => 1456957782 [:db_insert_placeholder_9] => 1 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => 1 [:db_insert_placeholder_13] => ) in Drupal\Core\Database\Connection->handleQueryException() (line 673 of /Users/micahjoyner/www/cmm.dev/core/lib/Drupal/Core/Database/Connection.php).
Created an issue for it here:
https://www.drupal.org/node/2679907
Comment #14
mhmd commentedI see its a bug, the entity system must prevent hiding required fields or require to set default values like other fields.
The big problem is that the field itself not exists in the form array so gives DB error as reported above in #11 && #12.
Comment #15
lilbebel commentedI am having the same error when I try to save a content type.
Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: node_field_data.title: INSERT INTO {node_field_data} (nid, vid, type, langcode, title, uid, status, created, changed, promote, sticky, revision_translation_affected, default_langcode, content_translation_source, content_translation_outdated) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); Array ( [0] => 103 [1] => 103 [2] => practitioners [3] => en [4] => [5] => 1 [6] => 1 [7] => 1465214657 [8] => 1465215397 [9] => 0 [10] => 0 [11] => 1 [12] => 1 [13] => und [14] => 0 ) in Drupal\Core\Database\Connection->handleQueryException() (line 668 of /home/mywebsite/public_html/core/lib/Drupal/Core/Database/Connection.php).
Just to be clear, when referring to 'title', does that mean the label in 'Manage Display'?
I have posted about this here but want to make sure it is a duplicate before closing my initial post.
Thanks.
M
Comment #16
kriboogh commentedAny progress on this (2 year old problem) ? Or do we need to resolve to contrib modules solutions. But which one, cause they all seem to be in a non-stable dev state at the moment for D8 ?
Comment #18
cilefen commentedNodes requiring a title (this issue, a feature request) and the fact that the UI allows you to destroy the form by hiding the title field #2821507: Handle exceptions gracefully when saving node forms, a bug, are different.
Comment #22
dries commentedI can think of quite a few content types where a 'Title' field does not make sense, especially in the context of content created for IoT devices, chat bots and voice assistance. Not having a title creates some challenges for some of our administrative UIs though.
Comment #23
bhanuprakashnani commentedI have understood the issue. I have implemented the required changes on my localhost. What is the next step I should take? Should I submit a patch? I am a newbie, I have less experience. Hope I get some help. Thank you.
Comment #24
bhanuprakashnani commentedComment #25
bhanuprakashnani commentedI have been working on the bug but I couldn't find the file in which the code related to the "Title" block is present. Can someone give me a clue where can I find the file related to this?
Comment #26
cilefen commented@bhanuprakashnani That sounds interesting. The best way forward is to ask for a little help on Drupal's Slack on how to roll a patch. You can find me there if that works for you.
Comment #27
kriboogh commentedWhy not just allow to set a default value using tokens on the field settings of title and allow the title field to be hidden in the form. Then underneath, when saving a node the title field is filled in by replacing the tokens with the values from the other fields. Basically what autotitle did in D7.
Comment #28
rominronin commented@kriboogh - that would be a work-around, but it isn't a solution to the root issue.
Comment #29
imanoop commentedI was having the same problem on my Dev server.
One simple way is to use form_alter on your custom module and user
code for node form.
Thanks,
Anoop Singh
Comment #31
ssserkkk commentedWhere should I write the code below?
#29
$form['title']['widget'][0]['value']['#required'] = true;
Comment #32
ujin commented@ssserkkk create your custom module https://www.drupal.org/docs/8/creating-custom-modules create a module_name.module file and add hook_form_YOUR_FORM_ID_alter function and insert that code.
Comment #33
imclean commentedSome related links:
Comment #34
imclean commentedEntities use labels which can (or should) be configurable by entity type and potentially bundle. There should be no need for a title any more.
Comment #35
eahonet commentedMy work around for this is (thank you comment #4 @benelori)
Comment #36
karopka commented#35
can you explain how to setup Bussines Rules for this?
Comment #38
chandravilasComment #39
chandravilasComment #40
chandravilasPatch is created to restrict the title field from disabled, by applying this patch, users or admin users not able to disable this field and avoid the error during content addition.
Not possible to remove this field as this field is default field and it is also a mandatory field, so better to rename this field and use it.
Comment #41
chandravilasPatch is created to restrict the title field from disabled, by applying this patch, users or admin users not able to disable this field and avoid the error during content addition.
Not possible to remove this field as this field is default field and it is also a mandatory field, so better to rename this field and use it.
Comment #45
imclean commentedComment #47
sanjayk commentedI review the issue and found that Drupal 9.1.x onward, we have an option to hide the title file under "Manage form display" in core and it is working fine without any error.
As mentioned #27not required and as mentioned #16now no need to contributed module as well.
Comment #48
NitinLama commented@chandravilas i agree, it's better to rename a field_name and use it.
Comment #50
pameeela commentedAdded credit for folks from #3069205: "The website encountered an .." after hide the node title, I closed it as a duplicate.
Comment #51
vikashsoni commentedI applied #40 patch By this patch we can not disable the title field from form-display setting. sharing screenshot...
Comment #53
quietone commentedClosed #2743663: Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: as a duplicate.
Comment #57
dieterholvoet commentedI set
setStorageRequired(FALSE)on the title base field. That way, the title field stays required by default, but if it is made optional (eg. by hiding in form display or by creating a base field override) no database errors will happen.Comment #58
akhildev.cs commentedhi,
I have applied and tested patch #56. patch applied cleanly but it's not fine for me.
It seems that we can not hide the title field by 'form display' it will cause an error when adding new content.
(The same database error as above mentioned. screenshot attached)
Comment #59
dieterholvoet commentedDon't forget to run database updates after applying the patch.
Comment #60
akhildev.cs commentedHI, Patch #56 is working fine.
I apologize for that, I forget about the database update after the patch was applied,
Patch #56 was applied cleanly and working fine. (title field can hide from 'form display').
Comment #63
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #65
manibharathi ezhimalai ravi commentedHi,
Since not able to create the branch for the latest version Drupal 11.x.
So Attaching the rerolled patch file for the core version 11.x.
Comment #66
manibharathi ezhimalai ravi commentedComment #67
tolstoydotcom[Copying from the since closed "Hiding the node title makes node form submission crash #3397765: Hiding the node title makes node form submission crash"]
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.
Comment #68
arunkumarkComment #69
arunkumarkComment #70
yasminorj commentedHi,
I tried patch #65 in Drupal 11.x , but it didn’t work for me. I’m sharing the error that appears when I hide the field and try to save a node without a title.
Comment #71
smustgrave commentedFixes should be in MRs
Issue summary appears to be missing sections too. Probably could use a title update too as that's very miss leading.
Comment #79
arunkumarkCreated MR for the 11.x version. Moving to NR.
Comment #80
supriyak commentedHi,
Changed title from 'Do not require a 'title' field' to 'Remove 'not null' constraint from node title field/column.('Title' field present in node entity should not be mandatory.)'.
Thanks!
Comment #81
smustgrave commentedSee tags
Comment #82
acbramley commentedI'm not really sure if this is something core should support to be honest.
As expected, when you have a node with a NULL title a LOT of other things break horribly.
Just to name a few in the first few minutes of testing this:
1. You can't save a node because
NodeForm::saveuses the node's title in 2 places: the log context'%title' => $node->label(), and the t_args with$node->toLink()(EntityBase::toLinkdoes not fail gracefully when $text is NULL and$this->label()returns NULL). Both of these throw fatal errors with a NULL title.2. Once manually fixing the above I get a message
Article has been created., that's not very helpful, but at least the view page works.3. The Edit form throws a fatal error because the title is
Edit @type @titlewhere @title is$node->label()4. The Revisions page throws a fatal error because the title is
Revisions for %title5. Deleting a node throws a fatal error because it tries to print a message
The @type %title has been deleted.And I'm sure there are many, many more examples.
The
labelfunction has to be able to return NULL because an entity type can have no label defined. There is an argument I suppose that all of these places should account for a NULL label return but given 99% of sites probably don't need this it doesn't seem like it passes the bar to be part of core.Given contrib/custom modules can modify the base field definition to removing the required/not null flags I'm wondering if this should be closed as won't fix?
Comment #83
acbramley commentedIt has been 5 months since #82, wanted to give this one last bump before closing it.