Problem/Motivation

admin/content/book/* page allows editors to update the book titles etc.
On this page if node title is not set, it still allows to save the book pages form.
Because of that, node title becomes empty and thows following errors

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Core\Entity\EntityStorageException</em>: SQLSTATE[23000]: Integrity constraint violation: 1048 Column &#039;title&#039; cannot be null: INSERT INTO {node_field_data} (nid, vid, type, langcode, status, title, uid, 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] =&gt; 12
    [:db_insert_placeholder_1] =&gt; 53
    [:db_insert_placeholder_2] =&gt; book
    [:db_insert_placeholder_3] =&gt; en
    [:db_insert_placeholder_4] =&gt; 1
    [:db_insert_placeholder_5] =&gt; 
    [:db_insert_placeholder_6] =&gt; 0
    [:db_insert_placeholder_7] =&gt; 1502214772
    [:db_insert_placeholder_8] =&gt; 1502619299
    [:db_insert_placeholder_9] =&gt; 0
    [:db_insert_placeholder_10] =&gt; 0
    [:db_insert_placeholder_11] =&gt; 1
    [:db_insert_placeholder_12] =&gt; 1
)

Steps to reproduce

- Create a book and visit the edit page at "admin/content/book/{book_id}"
This page lists all the child pages/chapers in the book where we can re-arrange or change title for the page.
- Give the empty tile for the any node.
- It still allows editors to submit the form with empty title.
- Actually, title field is node title, so we should ensure that it is not empty.
- If left empty, it will throw the errors mentioned above.

Proposed resolution

- Add validation constraints on the form to validate if title is not empty.
- Add other necessary validation in place.

Remaining tasks

- Fix is implemented.
- Added test cases.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

webchick’s picture

Priority: Critical » Normal
derjochenmeyer’s picture

Version: 7.x-dev » 8.x-dev
Status: Active » Needs review
FileSize
727 bytes

Set an error for empty node titles:

  foreach ($form_state['values']['table'] as $key => $book_admin) {
    if (empty($book_admin['title'])) {
      form_set_error("table][$key", t("You are trying to submit an emtpy node title. Please enter a title for every node."));
    }
  }
enhdless’s picture

Issue summary: View changes
Status: Needs review » Needs work

Patch no longer applies, should be rerolled.

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.

Sweetchuck’s picture

Issue summary: View changes
Sweetchuck’s picture

Status: Needs work » Needs review
Issue tags: +Drupalaton 2017
FileSize
4.83 KB
Sweetchuck’s picture

Sweetchuck’s picture

The last submitted patch, 9: drupal-1169576-9-book-title-validation.patch, failed testing. View results

The last submitted patch, 10: drupal-1169576-10-book-title-validation.patch, failed testing. View results

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
quietone’s picture

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

I tested on Drupal 9.4.x and this is still an problem. The issue summary does not have a proposed resolution so only looked at the patch to see if there are tests. There are not, so adding tag.

This needs an issue summary update, see an-existing-issue">Write an issue summary for an existing issue for guidance.

Suresh Prabhu Parkala’s picture

FileSize
4.57 KB

A re-rolled patch against the latest 9.4.x.

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

mohit_aghera’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
6.22 KB
6.35 KB

- Perform bit of code refactoring.
- Add test cases.
- Add issue summary update.

ameymudras’s picture

Thanks @mohit_aghera, I have tested the patch on 9.5.x and php 8.1 and the patch #23 fixes the issue. The only suggestion here is to use dependency injection here and to avoid \Drupal calls

$form[$id][$field_name]['#prefix'] = !empty($indentation) ? \Drupal::service('renderer')->render($indentation) : '';

pooja saraah’s picture

Thanks for the suggestion @ameymudras on #24
I have attached the patch for Drupal 9.5.x

Status: Needs review » Needs work

The last submitted patch, 25: 1169576-25.patch, failed testing. View results

narendra.rajwar27’s picture

Status: Needs work » Needs review
FileSize
8.2 KB

Fix added for failed test case. Added DI for Renderer service. Interdiff could not be generated.

DeepaliJ’s picture

Assigned: Unassigned » DeepaliJ
DeepaliJ’s picture

Assigned: DeepaliJ » Unassigned

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Removing tests and issue summary updates from #23 thanks!

Verified this by following the steps in the IS

-            $node->book['link_title'] = $values['title'];
+            $node->setTitle($values['title']);

Not sure how this applies to the validation?

Will let the committer decide if that matter.

This patch does not apply to 10.1 so will have to be ported.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 1169576-27.patch, failed testing. View results

quietone’s picture

Status: Needs work » Postponed

This extension is being deprecated, see #3376070: [Meta] Tasks to deprecate Book module. It will be removed from core and moved to a contrib project, #3376101: [11.x] [Meta] Tasks to remove Book.

This is now Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.

This issue may be re-opened if it can be considered critical, If unsure, re-open the issue and ask in a comment.

Version: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.