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.
$type->has_title = $type->has_body = TRUE;
WTF?? In the form, we take care to honor these settings and here we destroy them?
Comment | File | Size | Author |
---|---|---|---|
#16 | content_types_2.patch | 3.21 KB | drumm |
#15 | content_types_1.patch | 3.15 KB | drumm |
#6 | content_types.inc.patch | 1.84 KB | KarenS |
node_type_honor_labels.patch | 1.13 KB | chx | |
Comments
Comment #1
KarenS CreditAttribution: KarenS commentedSame problem here, particularly with CCK types that should have no body which have 'has_body' reset to true every time you edit the content type. This patch fixes the problem and I think it is RTBC.
Comment #2
Dries CreditAttribution: Dries commentedWhy is this critical? How to reproduce this? (Would be great if Neil could take a look at this -- he might have authored that piece of code. Not sure.)
Comment #3
chx CreditAttribution: chx commentedErm, this is likely written by *blush* me (or Jaza) as we have written most of the preCCK patch.
How to repro? Not too easy, I admit. Maybe create a node type, and in the database change its has_ttle attribute. Or check out CCK , patch it up so it runs more or less with D5... well, this is critical because as Karen points out it breaks CCK.
Comment #4
KarenS CreditAttribution: KarenS commentedTo reproduce this, manually set has_body to false on a content type (which is what cck is going to do when it passes in content types created in 4.7). Then edit the content type and has_body will get reset to true.
This is complicated by the fact that there is no way to set has_body to turn it off when creating a new type, which will also be needed for the 5.0 port of CCK, but I didn't want to pollute this issue with another one. I'll need to create another issue for this.
I personally don't care about has_title, but the point of the patch is that it is arbitrarily resetting values, and I can't see any reason why it should do that.
Comment #5
KarenS CreditAttribution: KarenS commentedNow that I think about it, I have a more comprehensive solution to propose.
CCK does not use the body field and the node_types table has a value has_body which can be set to false, but the form has no way to indicate that you want no body in the type you are creating/editing, plus it makes the body label field a required field. The form needs to be altered to allow for types with no body. It could be done by making the body label a non-required field, adding in a description which says if the label is empty no body will be provided, and then changing the submit code to update the value in the node_types table appropriately (set has_body to false if there is no label, otherwise to true).
The submit code also needs to remove the item which forces that value to TRUE, as this patch does.
I don't have time to make a patch right now, but will try to get back to this later if no one else does.
Comment #6
KarenS CreditAttribution: KarenS commentedActually, chx's patch handled the submit part fine, but we need to make the fields not required and add some explanatory text, so here is a re-rolled patch with those two items.
Comment #7
drummI'm okay with body. Leaving that out can make sense in some cases and doesn't cause any real problems I can think of.
Title is a bit trickier. I do think that there are valid (but how often?) cases for it. However, the content administration page and other places assumes titles will exist. Maybe do just enough so that strange things can be done with titles using hook_form_alter() (or other appropriate API), but not with vanilla core?
Comment #8
drummComment #9
greggles@drumm - in response to your question in #7 requesting the ability to remove the title from the form and replace it with default text, I believe the auto_nodetitle module does that http://drupal.org/project/auto_nodetitle
Is that what you were looking for? I'm assuming that module could be easily upgraded and work in 5.x. In that case this could be RTBC.
Comment #10
drummGreat, that module can handle doing the necessary form alterations to set up the titles. Core needs to stay as functional as possible with every configuration possibility, so that means titles are required in Drupal core without any modules.
Comment #11
gregglesSo, I apparently don't understand this issue well enough. My apologies.
Comment #12
KarenS CreditAttribution: KarenS commentedI'm fine with making the title required so long as the body is not. I am not where I can re-roll the patch right now, though. If no one else does it, I'll try to get back and do it later.
Comment #13
chx CreditAttribution: chx commentedWe removed mandatory title at least one (maybe two?) release ago. I am using a non titled node, it works flawlessly. This is a 'singleton' node, noone has the create rights for this nodetype and nodeadmins know better than to create another and there is a menu item pointing to it. The content admin screen also works, you can't click on the title, for there is no link but oh well, it's in the menu anyways. There is a use case which does not use anything but core and has no title. Do not take flexibility away.
Comment #14
drummThe ability to have non-titled node types has been in the API, but never implemented in core itself. As chx mentions, there are some hoops to jump through, like creating a menu item and educating administrators, if you do have non-titled content types. I do think non-titled node types should be possible, as they were previously.
Attached is a patch which gives full control of the body field's existence, with less code. It keeps nodes with title fields having title fields, prevents node types without title fields from acquiring a title field, and doesn't get in the way of any module which modifies the form and this behavior. It fixes a undefined array issue when there isn't a title or body field.
Comment #15
drummComment #16
drummchx pointed out that I might want to make that field non-required when disabled.
Comment #17
Jaza CreditAttribution: Jaza commentedSorry, I think it's me that was responsible for the
$type->has_title = $type->has_body = TRUE;
line of code. IIRC, I put it in so thattitle
andbody
would always be forced to be present for user-defined node types. For module-defined node types, this code isn't meant to kick in. But I guess that in the case of CCK node types, they end up being halfway between user-defined and module-defined, and this code ends up stopping them from being as flexible as they should be.What should we be testing this patch with? Core CVS + CCK CVS?
Comment #18
KarenS CreditAttribution: KarenS commentedThis works fine for me. I tested by manually changing a content type to have zero values for has_title and has_body, and then tried to edit the type and make sure those types did not get reset, and they did not (previously they did).
One minor nit, we lost the description for the title field if the field is editable.
Comment #19
drummI decided that "The label for the title field of this content type." wasn't adding much explanation since the label is "Title field label."
Comment #20
drummThis is for testing on CVS core only. I haven't checked in with CCK contrib lately and don't know how ready it would be to test with CVS.
Comment #21
KarenS CreditAttribution: KarenS commentedCCK should work fine with cvs now.
Comment #22
KarenS CreditAttribution: KarenS commentedIn addition to testing it by manually changing the content type, I have now tested it with latest cvs of Drupal and CCK and it seems to work fine. I think it's RTBC.
Comment #23
amitaibuAs seen here - it is also important for us the CCK users :)
Comment #24
mcreature CreditAttribution: mcreature commented+1 to get this commited
Comment #25
drummFor the record, I'm not committing this since I wrote the last version, which I think is ready to go.
Comment #26
dodorama CreditAttribution: dodorama commented+1 to get this committed. CCK users can't live without it.
Comment #27
chx CreditAttribution: chx commentedDries? Steven?
Comment #28
Dries CreditAttribution: Dries commentedCommitted! Thanks!
Comment #29
(not verified) CreditAttribution: commented