Currently $variables[flag_classes] is created in template_preprocess_flag() right after flag_classes_array is created. This doesn't give the theme a chance to alter the class array before the variable is created for use in the template. A workaround is to alter the array in preprocess from the theme then recreate the $flag_classes variable, but this seems inconsistent with other templates such as node and block.

Comments

joachim’s picture

Version: 7.x-2.0 » 7.x-3.x-dev
Status: Active » Postponed (maintainer needs more info)

Can't you do:

function mytheme_preprocess_flag(&$vars) {
  // Let flag do its work.
  template_preprocess_flag($vars);
  // Now change it!
  // ...
}

If that won't work, could you explain more what you mean by:

> from preprocess to process

or better yet, write a patch?

joachim’s picture

Oh I think I see what you mean for the problem at least:

  $variables['flag_classes'] = implode(' ', $variables['flag_classes_array']);

you mean that these classes are already imploded and you can't easily remove some?

pixelwhip’s picture

Yep, #2 is exactly what I meant. There are number of workarounds. It just threw me for a loop because altering $variables['flag_class_array'] won't do anything unless you reimplode it.

Zarabadoo’s picture

StatusFileSize
new1.32 KB

Here is a patch to get this started.

ultimateboy’s picture

Status: Postponed (maintainer needs more info) » Needs review

Setting status.

joachim’s picture

Status: Needs review » Needs work
+++ b/flag.module
@@ -1613,6 +1609,18 @@ function template_preprocess_flag(&$variables) {
+ * A process function for our theme('flag'). This converts class arrays to
+ * strings.

Function summary should one line and a single sentence.

I would move 'This converts class arrays to' to an inline comment.

We should document @param variables, even if very very briefly!

(I see you've followed the model of the preprocess function, but that's all wrong!)

socketwench’s picture

Status: Needs work » Needs review
StatusFileSize
new1.39 KB

Moved like to inline comment, added a @param.

joachim’s picture

Status: Needs review » Fixed
StatusFileSize
new1.38 KB

Fixed the wording of the docbloc.
Replaced a very crusty join() with an implode() while we're at it.

git commit -m "Issue #1793572 by Zarabadoo, socketwench: Changed the creation of CSS class variables from being handled in theme preprocessor to theme processor." --author="zarabadoo "

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.