Both Flat Collapsed viewing mode and the Newest First sort order are broken in all 4.7.x versions.
This is because they are defined as 0:
define('COMMENT_MODE_FLAT_COLLAPSED', 0);
define('COMMENT_ORDER_NEWEST_FIRST', 0);
In the function comment_render, there is a test to see if viewing mode and viewing sort order are set:
if (empty($mode)) {
$mode = $user->mode ? $user->mode : ($_SESSION['comment_mode'] ? $_SESSION['comment_mode'] : variable_get('comment_default_mode', COMMENT_MODE_THREADED_EXPANDED));
}
if (empty($order)) {
$order = $user->sort ? $user->sort : ($_SESSION['comment_sort'] ? $_SESSION['comment_sort'] : variable_get('comment_default_order', COMMENT_ORDER_NEWEST_FIRST));
}
Both Flat Collapsed and Newest First will evaluate false in empty() as well as the if statements:
$mode = $user->mode ? $user->mode :
$order = $user->sort ? $user->sort :
Which means as soon as you select those options, it gets reverted to the default.
The simple fix is to change the constants:
define('COMMENT_MODE_FLAT_COLLAPSED', 1);
define('COMMENT_MODE_FLAT_EXPANDED', 2);
define('COMMENT_MODE_THREADED_COLLAPSED', 3);
define('COMMENT_MODE_THREADED_EXPANDED', 4);
and
define('COMMENT_ORDER_NEWEST_FIRST', 1);
define('COMMENT_ORDER_OLDEST_FIRST', 2);
I'm not sure how to go about getting this changed, so could someone please help me out?
Thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | comment.controls_0.patch | 5.41 KB | tenrapid |
| #16 | comment.controls.patch | 6.49 KB | tenrapid |
| #13 | user_comment_mode.patch | 2.99 KB | Jaza |
| #9 | comment.module_56.patch | 1.28 KB | tenrapid |
| #3 | comment.constants.patch | 1.13 KB | tenrapid |
Comments
Comment #1
yourhiro commentedComment #2
killes@www.drop.org commentednot a patch yet, but I'd sure like to see one.
Comment #3
tenrapid commentedThe question is if CONSTANTS are considered to be zero based or not.
If not: here's a patch.
Comment #4
tenrapid commentedhrrmpf ...
Comment #5
markus_petrux commentedDoes this need an update step to migrate current values?
Comment #6
tenrapid commentedNo, the values in Drupal 4.6 are the same as in my patch.
Comment #7
tenrapid commentedHmm, there is already an update step that decrements these entries by one in the variable table -> system_update_174().
So I'll probably have to come up with another patch that changes the logic instead of the values.
Comment #8
markus_petrux commented:)
Comment #9
tenrapid commentedNew patch keeps the zero based constants and changes the logic instead.
Comment #10
dries commentedWorks. Committed to CVS HEAD.
Comment #11
Zen commentedHEAD: All comment views appear to be defaulting to 0 atm. This could be because of the fact that $user->mode always defaults to 0.
-K
Comment #12
tenrapid commentedAfter all I'm for making these two constants based on one again as it is in Drupal 4.6.
Keeping them zero based would require more code and logic:
- change default value of the columns 'mode' and 'order' in the {users} table to NULL
- extend the update step 174 to accomadate above columns to these changes
So what is the way to go?
Comment #13
Jaza commentedAttached patch preserves the constants starting at zero, and changes the 'mode' field in the 'users' table to be NULL by default. This fixes the problem of comments always being displayed in 'flat collapsed' mode, unless comment controls are available and the user explicitly selects another mode using these controls.
This patch also looks for all instances where the 'mode' field in 'users' is set to 0, and changes it to NULL. This results in some loss of data, but unfortunately there's no way to avoid that. For sites where:
(a) the default viewing mode is NOT 'flat collapsed',
(b) users are able to set their own viewing mode using the comment controls, and
(c) the user has set their mode to 'flat collapsed',
users will simply have to set the viewing mode again (a very minor inconvenience for them, IMO). For any scenarios other than the exact one described above, comment viewing remains the same (i.e. users are unaffected).
I think that having the constants start at zero is a good thing (as a principle, and for consistency with other Drupal constants). And in order to get those zero-based constants working, this patch is necessary.
Comment #14
Jaza commentedOh, and I should add: the above patch was tested with mysql and pgsql.
Comment #15
markus_petrux commentedI have marked this issue as a dup of this one:
http://drupal.org/node/60214
It's not the same problem, but it's pretty related. Please, consider fixing the problem described in that issue here.
Comment #16
tenrapid commentedHere is a new patch.
I moved the whole display settings logic out of
comment_render()and move it into a new function_comment_get_display_setting($setting). I also incorporated the changes to fix markus' issue.Also Jaza forgot the sort column so I added it.
Comment #17
Zen commentedLooks good. Also tested with and without comment controls - does the trick.
Thanks
-K
Comment #18
Jaza commentedVery nice. I like the approach of moving all this checking to a separate function, and of making the code more generic. +1.
One question: if the user selects their own value for 'comments_per_page', where does that get saved? There's no field for it in the 'users' table, so I assume it gets serialized and put in the 'data' column... correct? And if so, I guess it's essentially a 'default NULL' field (since it won't get put into 'data' until the user sets a value for it).
Comment #19
moshe weitzman commentedgroups.drupal.org is now sufferring from this. if possible, please commit this at earliest opportunity.
Comment #20
kayfish commentedI believe that this is my issue also, submitted under:
http://drupal.org/node/60340
I'll mark the other as a duplicate
Comment #21
dries commented* The function could do with some additional code comments.
*
$value = isset($user->$setting) ? $user->$setting : (isset($_SESSION['comment_'. $setting]) ? $_SESSION['comment_'. $setting] : $default);is kinda long.Comment #22
gerhard killesreiter commentedI'd prefer to change the constants, fix update 174, and leave the database alone if possible at all. We only need to provide an upgrade patch from 4.6 to 4.7.
Comment #23
yourhiro commentedPardon my inexperience (in web programming/oss/drupal) but, what ever happened to the whole KISS principle? Why add more logic, function calls, etc when simply changing the constants does everything we need?
It seems like a whole lot of extra work for the sake of...I'm not sure, which is why I'm asking :)
And referring to 0-based constants, what's the benefit(s)? I can understand if it's a binary variable...but when it's not, why make 1 of n constants in a set a "special" value?
Thanks
Comment #24
tenrapid commentedThese constants, well, zero or not, t. i. t. q.
The corresponding user table columns 'mode' and 'sort' exist there for 5 years now and IMO they should go into the 'data' column. But because this won't happen and in a sense of tradition this new patch keeps the database untouched and changes the constants instead. Back to their 4.6 values.
The patch also fixes (removes) the update step 174, incorporates Dries' comment and removes some crufty pager comments and code.
Comment #25
killes@www.drop.org commentedthis looks very promising. Any testers? Especially the update from 4.6 shoudl be tested.
Comment #26
rkerr commentedI haven't tested but will +1 the #24 approach.
Comment #27
Steven commentedAfter this patch, the integer values used by 4.6 and 4.7 are the same. So the update can indeed be removed (but should be left in there to ensure consistent updating).
Committed to HEAD, thanks.
Comment #28
(not verified) commented