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:

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.

Issue fork drupal-2358537

Command icon 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

brylie’s picture

brylie’s picture

benelori’s picture

You 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.

brylie’s picture

Thanks 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.

benelori’s picture

Yes 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.

berdir’s picture

Component: entity system » node system

This is about the node entity type, not the entity system.

brylie’s picture

Thanks @benelori and @Berdir for the clarification that this is related to the node system. :)

ivarlaks’s picture

Issue summary: View changes
dimitrov.adrian’s picture

When 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.

alex.barylski’s picture

@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:

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) 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] => 4 [:db_insert_placeholder_1] => 4 [:db_insert_placeholder_2] => inventory [:db_insert_placeholder_3] => en [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => 1452532021 [:db_insert_placeholder_8] => 1452532021 [:db_insert_placeholder_9] => 0 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => 1 ) in Drupal\Core\Database\Connection->handleQueryException() (line 673 of /var/www/drupal/web/core/lib/Drupal/Core/Database/Connection.php).

Am I missing a step in D8 (8.0.2)???

This would be nice not to have to worry about :)

mcvjoyner’s picture

@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

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mhmd’s picture

I see its a bug, the entity system must prevent hiding required fields or require to set default values like other fields.

those set to not null in DB and created by default with entity definition like title in nodes

The big problem is that the field itself not exists in the form array so gives DB error as reported above in #11 && #12.

lilbebel’s picture

I 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

kriboogh’s picture

Any 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 ?

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

cilefen’s picture

Nodes 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.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dries’s picture

I 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.

bhanuprakashnani’s picture

I 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.

bhanuprakashnani’s picture

Assigned: Unassigned » bhanuprakashnani
bhanuprakashnani’s picture

I 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?

cilefen’s picture

@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.

kriboogh’s picture

Why 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.

rominronin’s picture

@kriboogh - that would be a work-around, but it isn't a solution to the root issue.

imanoop’s picture

I was having the same problem on my Dev server.
One simple way is to use form_alter on your custom module and user

$form['title']['widget'][0]['value']['#required'] = true;

code for node form.

Thanks,
Anoop Singh

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ssserkkk’s picture

Where should I write the code below?

#29

$form['title']['widget'][0]['value']['#required'] = true;

ujin’s picture

@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.

imclean’s picture

Entities use labels which can (or should) be configurable by entity type and potentially bundle. There should be no need for a title any more.

eahonet’s picture

My work around for this is (thank you comment #4 @benelori)

  1. use Display Suite to hide the Title on the display
  2. move the title field out of the Form Manage area so it's not even shown on the node submit
  3. Use the module Business Rules to create a rule that if a node has an empty title, assign the title field a new value of "New Node Type By [currentuserid]".
karopka’s picture

#35

can you explain how to setup Bussines Rules for this?

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

chandravilas’s picture

chandravilas’s picture

chandravilas’s picture

Status: Active » Needs work
StatusFileSize
new1.63 KB

Patch 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.

chandravilas’s picture

Status: Needs work » Needs review

Patch 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.

Status: Needs review » Needs work

The last submitted patch, 40: drupal_core-field-ui-2358537-13142798-8.8.x-dev.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

imclean’s picture

Issue summary: View changes

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

sanjayk’s picture

Status: Needs work » Needs review

I 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.

NitinLama’s picture

@chandravilas i agree, it's better to rename a field_name and use it.

pameeela credited freelylw.

pameeela’s picture

Added credit for folks from #3069205: "The website encountered an .." after hide the node title, I closed it as a duplicate.

vikashsoni’s picture

StatusFileSize
new153.32 KB
new159.42 KB

I applied #40 patch By this patch we can not disable the title field from form-display setting. sharing screenshot...

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

DieterHolvoet made their first commit to this issue’s fork.

dieterholvoet’s picture

I 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.

akhildev.cs’s picture

StatusFileSize
new20.68 KB
new130.55 KB

hi,
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)

dieterholvoet’s picture

Don't forget to run database updates after applying the patch.

akhildev.cs’s picture

StatusFileSize
new98.76 KB
new64.94 KB
new41.33 KB

HI, 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').

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new150 bytes

The 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.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

manibharathi ezhimalai ravi’s picture

StatusFileSize
new1.92 KB

Hi,
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.

manibharathi ezhimalai ravi’s picture

Status: Needs work » Needs review
tolstoydotcom’s picture

[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.

arunkumark’s picture

Version: 11.x-dev » 11.0.x-dev
arunkumark’s picture

Version: 11.0.x-dev » 11.x-dev
yasminorj’s picture

StatusFileSize
new77.05 KB

Hi,
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.

issue error

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs issue summary update

Fixes 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.

supriyak made their first commit to this issue’s fork.

arunkumark changed the visibility of the branch 2358537-do-not-require to hidden.

arunkumark changed the visibility of the branch 9.4.x to hidden.

arunkumark’s picture

Status: Needs work » Needs review

Created MR for the 11.x version. Moving to NR.

supriyak’s picture

Title: Do not require a 'title' field » Remove 'not null' constraint from node title field/column.('Title' field present in node entity should not be mandatory.)

Hi,

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!

smustgrave’s picture

Status: Needs review » Needs work

See tags

acbramley’s picture

Status: Needs work » Postponed (maintainer needs more info)

I'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::save uses the node's title in 2 places: the log context '%title' => $node->label(), and the t_args with $node->toLink() (EntityBase::toLink does 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 @title where @title is $node->label()

4. The Revisions page throws a fatal error because the title is Revisions for %title

5. 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 label function 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?

acbramley’s picture

It has been 5 months since #82, wanted to give this one last bump before closing it.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.