Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Block module is not providing a default subject on inserts.
When adding a block and not giving it a subject the module commits a null to the database. Then if this block is enabled and the theme doesn't take care of checking subject it yields an error:
notice: Undefined property: stdClass::$subject
This patch defaults subject to ''.
Comment | File | Size | Author |
---|---|---|---|
#16 | block_subject.patch | 773 bytes | Pasqualle |
#10 | block_subject_default_d.patch | 869 bytes | theborg |
#6 | block_subject_default_c.patch | 3.59 KB | theborg |
#3 | block_subject_default_b.patch | 768 bytes | theborg |
#1 | block_subject_default_b.patch | 770 bytes | theborg |
Comments
Comment #1
theborg CreditAttribution: theborg commentedAnother way would be committing 'none' if the user is not providing the title.
Comment #2
Gábor HojtsyWhy not save the empty string?
<none>
is not translation compatible in itself. Also you have spacing issues in your patch.Comment #3
theborg CreditAttribution: theborg commentedCorrection of the spacing issues.
I am defaulting to
<none>
because is the standard way of creating a block without a title.Comment #4
Gábor Hojtsytheborg: Is actually
<none>
gets saved into the db, when you enter it on the web interface?Comment #5
theborg CreditAttribution: theborg commentedYes, it is a way to say that the block doesn have a title, as you can see in blocks table.
@gabor: Do you consider it better to have an empty value?
Comment #6
theborg CreditAttribution: theborg commented- Added an explanation to make aware the user of the title possibilities when creating a block:
a) Title is blank => uses description as a title
b)
<none>
=> no title is displayed- Added translation of
none
.- Added a constant BLOCK_TITLE_NONE that defaults to -1 to block module.
Marking this critical because it produces an error if the theme template is not taking care of block->subject and therefore the user can not build css-only themes.
Comment #7
Gábor HojtsyA little theme error for block titles does not make this critical.
- We don't do br tags in form item descriptions.
- Instead of concatenating t()-ed text, which breaks the flow, and makes it impossible to reorder things in languages which requires the contents to be reordered, use placeholders, such as @none if you think this needs a placeholder.
-
<none>
was not translatable before, why make it translatable now?- storing -1 in a string field to denote 'no title' is not exactly elegant, why is the previous way buggy?
Comment #8
theborg CreditAttribution: theborg commented@Gábor:
So, are you ok with #3?
Comment #9
Gábor HojtsyHm, my problem was that I did not understand why we need to fiddle with this in the validation. How does a NULL end up in the title value? On first thought it is because it is unset. But then it would give you a notice on submission. So when I looked into block_admin_configure(), I realized that there is actually an SQL query filling in the default values, which does not produce values if there was no data for the block at hand. So why not fix this at the root of the problem and only fill in the data from the database, if it was actually found there? db_fetch_array() seems to return FALSE if there was no result, right? So why not check for that and fill in an array with sensible defaults in this case.
I wonder why you did not receive a notice here for nonexistent blocks anyway. Hm.
Comment #10
theborg CreditAttribution: theborg commentedRevised this issue and got some conclusions:
1) NULL is not commited, that was _my fault_, sorry, I didn't notice that the table doesn't allow nulls on this values and that you always get an empty string from the form api.
2) The blocks creation form allows the user to enter no title, so its correct to think that the block should display no title.
3) The blocks configuration form allow the user to override the title of system blocks and this is when
<none>
gets commited.So, this patch only takes care of setting $block->subject to avoid notices letting the user decide to put a title or none at all.
Comment #11
Pasquallewhy is the check
if ($block->module == 'block')
necessary?Comment #12
PasqualleI would use something like this:
it would make these variables consistent
Comment #13
theborg CreditAttribution: theborg commentedBecause the default title for system blocks is an empty string, so it can be dynamically calculated (like user name for the navigation block). To override this you must enter
<none>
. In the case of custom blocks an empty title means no title.Comment #14
Pasqualleok, got it, (the user module sets the $block->subject variable, so it is wrong to change it)
but still does not seems good
then it should be something like isset($block->subject) check instead of module check
will try to debug..
Comment #15
Pasquallerepro steps:
1. remove
<?php if (!empty($block->subject)): ?>
- check from garland theme block.tpl.php2. admin/build/block/add - create block with description and body, but without title
3. admin/build/block - set region for the new block
notice: Undefined property: stdClass::$subject in ...\themes\garland\block.tpl.php on line 6.
Comment #16
Pasqualleand the patch
Comment #17
mpare CreditAttribution: mpare commentedPatch applies cleanly and appears to fix issue. I've created blocks with and without title, moved around, switched themes, switched themes back, deleted and created blocks, and edited existing blocks. Patch appears to fix stated issues without ill effect. Tested against fresh update of cvs head.
-mpare
Comment #18
Gábor HojtsyThanks, committed. This also fixes a pgsql error, as a NOT NULL value is required for any NOT NULL field.
Comment #19
(not verified) CreditAttribution: commentedAutomatically closed -- issue fixed for two weeks with no activity.