from sun's issue here: #849862: Bartik code problems
+++ themes/bartik/template.php 6 Jul 2010 03:48:59 -0000
@@ -0,0 +1,146 @@
+function bartik_process_page(&$variables) {
...
+function bartik_process_maintenance_page(&$variables) {
Both process functions partially contain identical lines, i.e., duplicate code. Those lines should be moved into a dedicated private helper function, e.g., _bartik_process_page(&$variables).
+++ themes/bartik/template.php 6 Jul 2010 03:48:59 -0000
@@ -0,0 +1,146 @@
+ // Always print the site name and slogan, but if they are toggled off, we'll
+ // just hide them visually.
+ $variables['hide_site_name'] = theme_get_setting('toggle_name') ? FALSE : TRUE;
+ $variables['hide_site_slogan'] = theme_get_setting('toggle_slogan') ? FALSE : TRUE;
These variables (and others) should be negated, i.e., into "show_xyz" or "toggle_xyz".
I've personally implemented and used similar "hide_xyz" template variables in custom themes some time ago, only to find out that a constant double negation of "hide foo" => FALSE ===> yes, TRUE is a super major source of confusion.
If you look closely at these lines, then you hopefully realize this problem already. Removing the double negation would lead to simplicity in
$variables['toggle_name'] = (bool) theme_get_setting('toggle_name');
Additionally, it slightly hurts my brain to see new flag names being introduced here, which require everyone to map "toggle_name" to "hide_site_name" and vice-versa. Effectively, not only a different name, but also negated meaning.
Final note for D8: We should auto-provision theme settings into a dedicated $variables['settings'] key for all templates by default, so as to simplify and remove all of this code from Bartik.
+++ themes/bartik/template.php 6 Jul 2010 03:48:59 -0000
@@ -0,0 +1,146 @@
+ // System menu blocks should get the same class as menu module blocks.
+ if (in_array($variables['block']->delta, array_keys(menu_list_system_menus()))) {
Faster:
if (($menus = menu_list_system_menus()) && isset($menus[$block->delta])) {
Comment | File | Size | Author |
---|---|---|---|
#29 | bartik-code-cleanup-850728-29.patch | 582 bytes | LewisNyman |
#25 | bartik-code_reuse_cleanup-850728-25.patch | 3.34 KB | toco |
#23 | bartik-code_reuse_cleanup-850728-20.patch | 3.22 KB | toco |
#20 | bartik-code_reuse_cleanup-850728-20.patch | 3.22 KB | kscheirer |
#16 | drupal-bartik-850728-16.patch | 3.58 KB | tim.plunkett |
Comments
Comment #1
bleen CreditAttribution: bleen commentedComment #2
sun1) It looks like the names have changed, but not the logic/values. I.e., FALSE is TRUE now. ;)
2) Ideally, some other theme and markup component freaks should comment here on the general variable naming. I'm still not sure whether it wouldn't be a better idea to just re-use the existing theme setting name, i.e., "toggle_name" instead of "show_site_name". For sure, toggle_name is not very clear, but at least, themers (should) already know what's contained and its meaning from the theme setting.
oh. Of course, these need to be fully updated, too.
43 critical left. Go review some!
Comment #3
bleen CreditAttribution: bleen commentedUPDATE: Ignore this patch ... see #4
Comment #4
bleen CreditAttribution: bleen commentedsorry ... lost some stuff in the shuffle when I broke up the big giant patch
Comment #5
tim.plunkettStraight reroll (#845928: System menu blocks don't get the same styling as menu module blocks removed code from bartik_preprocess_block).
I'll revisit this tomorrow.
Comment #6
tim.plunkettAfter some time thinking on this, and discussing it with some other themers, I really think this patch shouldn't go in.
Yes, normally show is used instead of hide, but in this case it shouldn't be.
Setting a variable that always needs to be negated in use is just extra work.
show_site_*
is ALWAYS preceded by!
, which is just another roadblock for PHP-noob themers.Also, having to write
if ($site_slogan) {... if (!$show_site_slogan) {...} }
seems very confusing and introduces ambiguity over the differences between$site_slogan
and$show_site_slogan
. The differences between$site_slogan
and$hide_site_slogan
are more evident.Just my 0.02 cents :)
Here's a reroll of just the helper function portion of the patch.
Comment #7
sunwell, I'm not Bartik's maintainer, but from a pure code and synaptic perspective, negated variables are almost always bad, since humans need to think around one more corner to understand the actual meaning. Most often, a constant source of bugs.
Also, when themers start to familiarize themselves with theme settings, those negated variables simply get weird. To understand the effect of the 'toggle_name' theme setting, you need to think. Don't make me think.
Comment #8
bleen CreditAttribution: bleen commentedI think in the case I need to agree with tim.plunkett... Given this change, $hide_site_slogan makes you think less than !$show_site_slogan.
I'm fine with #6 but I dont think I can mark it RTBC
Powered by Dreditor.
Comment #9
Jeff Burnz CreditAttribution: Jeff Burnz commentedWhy exactly are we hiding site name and slogan with element-invisible? I can somewhat understand site name, but site slogan? If I toggle this stuff off in theme settings I assume its not getting printed at all - gone, not hiding, I cant see a logical reason to leave either of these in the markup - can someone please explain the thinking here.
Comment #10
Jeff Burnz CreditAttribution: Jeff Burnz commentedI take it we're all in agreement here that we should not do this? Can we close this as a won't fix and clear one more away.
Is there anything from the original issue we need to still look at?
Comment #11
tim.plunkettThe patch at #6 just takes shared code from bartik_process_maintenance_page and bartik_process_page and moves it to _bartik_process_page, which is still a good idea IMO.
It still applies cleanly, can someone either RTBC or won't fix it?
Comment #12
Jeff Burnz CreditAttribution: Jeff Burnz commentedThis is the only thing in the function with no comment to explain what it is - maybe we need a comment here?
This entire comment refers to things that dont happen here...
This comment refers to the toggle setting, shouldn't it refer to the variable?
Docs/comments aside its good - either RTBC now and shift to a docs issue or fix em now and then RTBC?
Powered by Dreditor.
Comment #13
Jeff Burnz CreditAttribution: Jeff Burnz commentedComment #14
Jeff Burnz CreditAttribution: Jeff Burnz commented#6: drupal-bartik-850728-6.patch queued for re-testing.
Comment #15
tim.plunkettThis makes me really sad. It was basically RTBC three months ago, but it is way too late to change something like this. I blame myself for not following up.
Comment #16
tim.plunkettReroll for git, comment changes from #12.
Comment #17
kscheirerStill applies with small offset, reduces duplicate code, and Bartik still works for me after applying.
Comment #18
kscheirer#16: drupal-bartik-850728-16.patch queued for re-testing.
Comment #20
kscheirerOops, all the core/ paths changed, rerolled for HEAD.
Comment #21
valthebaldComment #22
toco CreditAttribution: toco commentedRerolling during core mentoring.
Comment #23
toco CreditAttribution: toco commentedSorry, I uploaded the wrong file here. The right one follows immediately
Comment #25
toco CreditAttribution: toco commentedComment #26
JurgenR CreditAttribution: JurgenR commentedReviewed patch #25, which is OK.
Maybe the documentation above _bartik_preprocess_node can be more generic as the focus doesn't need to be on site name and slogan only?
Comment #27
catchComment #29
LewisNymanIt looks like this patch added some unnecessary characters? It was throwing complaints in Sublime anyway.
Comment #30
star-szrIndeed, good catch @LewisNyman! Follow-up is RTBC.
Comment #31
alexpottCommitted 1ba7895 and pushed to 8.x. Thanks!
Should have really be a separate issue.