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 'title' 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] => 12
[:db_insert_placeholder_1] => 53
[:db_insert_placeholder_2] => book
[:db_insert_placeholder_3] => en
[:db_insert_placeholder_4] => 1
[:db_insert_placeholder_5] =>
[:db_insert_placeholder_6] => 0
[:db_insert_placeholder_7] => 1502214772
[:db_insert_placeholder_8] => 1502619299
[:db_insert_placeholder_9] => 0
[:db_insert_placeholder_10] => 0
[:db_insert_placeholder_11] => 1
[:db_insert_placeholder_12] => 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
Comment | File | Size | Author |
---|---|---|---|
#27 | 1169576-27.patch | 8.2 KB | narendra.rajwar27 |
#25 | interdiff_23-25.txt | 608 bytes | pooja saraah |
#25 | 1169576-25.patch | 6.2 KB | pooja saraah |
#23 | interdiff-1169576-21-23.txt | 6.35 KB | mohit_aghera |
#23 | 1169576-23.patch | 6.22 KB | mohit_aghera |
Comments
Comment #1
webchickComment #2
derjochenmeyer CreditAttribution: derjochenmeyer commentedSet an error for empty node titles:
Comment #3
enhdless CreditAttribution: enhdless commentedPatch no longer applies, should be rerolled.
Comment #8
SweetchuckComment #9
SweetchuckComment #10
SweetchuckComment #11
SweetchuckComment #20
quietone CreditAttribution: quietone at PreviousNext commentedI 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.
Comment #21
Suresh Prabhu Parkala CreditAttribution: Suresh Prabhu Parkala at Specbee commentedA re-rolled patch against the latest 9.4.x.
Comment #23
mohit_aghera CreditAttribution: mohit_aghera at PreviousNext commented- Perform bit of code refactoring.
- Add test cases.
- Add issue summary update.
Comment #24
ameymudras CreditAttribution: ameymudras at Salsa Digital commentedThanks @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) : '';
Comment #25
pooja saraah CreditAttribution: pooja saraah at Srijan | A Material+ Company for Drupal India Association commentedThanks for the suggestion @ameymudras on #24
I have attached the patch for Drupal 9.5.x
Comment #27
narendra.rajwar27Fix added for failed test case. Added DI for Renderer service. Interdiff could not be generated.
Comment #28
DeepaliJ CreditAttribution: DeepaliJ at Salsa Digital commentedComment #29
DeepaliJ CreditAttribution: DeepaliJ at Salsa Digital commentedComment #31
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis 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
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.
Comment #33
quietone CreditAttribution: quietone at PreviousNext commentedThis 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.