this code in alpha theme, causes entity.tpl.php to write the classes attribute twice to wrapper div.
and breaks w3c validation.

/**
 * Implements hook_preprocess().
 */
function alpha_preprocess(&$vars, $hook) {
  $vars['attributes_array']['class'] = $vars['classes_array'];
  
  alpha_invoke('preprocess', $hook, $vars);
}

so - $vars['classes_array'] should maybe - if possilbe ? - unset

probably a followup from #1835586: Preprocess ignores node #classes_array.

or is this more for the entity.module ?
when i see comments in the dev source like

// Sync that with the classes array. Remember: We don't recommend using it.

Comments

ytsurk’s picture

Issue summary: View changes

linked issue properly

ytsurk’s picture

Issue summary: View changes

removed missleading information

gdaw’s picture

joseph.olstad’s picture

Version: 7.x-3.1 » 7.x-4.x-dev
Priority: Normal » Major
Status: Active » Needs review
Related issues: +#2232467: wetkit_omega node.tpl is outputting 'class' twices

There is a D7 compliant patch for a similar issue in the wetkit_omega queue. To avoid double class attributes in a tag) you'll have to undo any hack attempts to do this (example) (example) in order to use the fix .

For those lucky souls that haven't attempted to fix the double class issue themselves and have waited for the fix , this is your lucky day. Here's how it was fixed in wetkit_omega (an omega derived theme) this patch to the template.php file in the wetkit_omega theme.

To fix this in "omega" someone will have to adapt the "wetkit_omega" fix for the "omega" theme.

We're fixing this in the wetkit_omega theme in our next release. It would be good if this was also fixed in the "omega" base theme at some point.

joseph.olstad’s picture

Status: Needs review » Needs work

It would be nice to see a fix for this in Omega

please see the comments here in the patch for wetkit_omega:

+/**
* Undo "moving `classes_array` into `attributes_array`" from Omega theme
*
* We prefer the classes array instead of the attributes array used by
* Omega, to stay in line with many core and contrib modules. In Drupal 7, we work
* the Drupal 7 way. In Drupal 8, we are going to do whatever is the Drupal 8 way.
* For now, we simply encourage themers to work as they usually work in Drupal 7.
*
*/

The lack of receptiveness in the omega queue to fix this is issue is likely one of the major reasons it has been dropped from my favourite drupal distro in future versions. Perhaps if this was fixed soon we could get back into omega and save us some work having to switch off of it.

While I did not write the sarcastic remark up above, it does make sense.

pkiff’s picture

Version: 7.x-4.x-dev » 7.x-3.1

I'm not a maintainer here, but I'm not sure this issue is set out as clearly as it might be in order resolve it.

To start with, I'm pretty sure that this issue does not apply to the 7.x-4.x version of Omega. There is no alpha theme in 4.x there, and I can't find comparable pieces of code in 4.x. I don't think this error is reproducible on Omega 4.x. That's not to say that Omega 4.x doesn't rewrite classes and attributes, but the code it uses to do this is entirely different.

It looks to me like this issue applies to Omega 7.x-3.x only, so I've changed the version back to 3.1. Omega 7.x-4.x represents a major structural change from 7.x-3.x and the code bases are maintained separately by different maintainers. However, I see that wetkit_omega says it is based on Omega 4.x. Is wetkit_omega is using a mixture of 3.x and 4.x templates and development strategies? Maybe this is clear to other developers, but I don't understand exactly where this is supposed to get fixed in Omega.

I have no opinion on whether this should be tagged as major or normal, so I have left that tag unchanged.

Followup:
Okay, so now I've found the code snippet that the wetkit_omega folks are referring to in this post:
https://www.drupal.org/node/2232467#comment-8892459
This snippet is found in the Omega 4.x-dev and 4.2 template.php file at lines 433+. But the various template files (for e.g., node.tpl.php) that this code interacts with do not contain the code snippet cited in the original post. Those snippets are from Omega 3.x versions of the template. It still leaves the issue unclear on where the fix should be in Omega, or indeed if this can even be called a "bug" in Omega if the issue is not reproducible in a standard 3.x or 4.x subtheme.

trinion’s picture

In my project outputting 'class' twice encountered in block wrappers.
I fix this trouble so:

/**
 * Implements hook_preprocess().
 */
function alpha_preprocess(&$vars, $hook) {
  if (!(strpos('block', $hook) === FALSE))
    return;
  $vars['attributes_array']['class'] = $vars['classes_array'];
  
  alpha_invoke('preprocess', $hook, $vars);
}
Madhuri A’s picture

Above code is not working, after adding still it showing duplicate attribute 'class' error

pkiff’s picture

@madhuri123:
To keep this thread and issue clear, can you confirm that you are using the wetkit_omega theme? Or are you using your own subtheme based on Omega 3.x or Omega 4.x?

rohittiwari’s picture

After a lot of juggling, found that alpha the base theme for omega theme's preprocess function has the highest weight in execution order, hence overriding the use of hook_preprocess for current site theme was not working. Tried to find a way to alter the preprocess execution order. Finally I have come up with small code snippet to alter theme registry inorder subsequently unsetting the attributes_array class array . @madhuri123 I am possibly providing a workaround which would solve the double class problem.

function Yourtheme_preprocess(&$variables, $hook){
  $hook_to_exclude = array('block', 'html','page','region','section','zone');
  $current_theme = 'omega';
  $merge = array_unique(array_merge($variables['classes_array'], $variables['attributes_array']['class']));
  if (in_array($hook, $hook_to_exclude) || strpos($current_theme, 'omega') === TRUE) {
    unset($variables['classes_array']);
    $variables['attributes_array']['class'] = $merge;
  }
  else{
    $variables['classes_array'] = $merge;
    unset($variables['attributes_array']['class']);
  }
}

function YourTheme_theme_registry_alter(&$registry) {
  foreach ($registry as $hook => $item) {
    $index = array_search('YourTheme_preprocess',$item['preprocess functions']);
    if ($index !== FALSE) {
      unset($registry[$hook]['preprocess functions'][$index]);
      array_push($registry[$hook]['preprocess functions'], 'YourTheme_preprocess');
    }
  }
}
pkiff’s picture

@rohittiwari:
Thanks for posting a possible solution to this issue. To help keep this thread and issue clear, can you confirm that you are using the wetkit_omega theme? Or are you using your own subtheme based on Omega 3.x or Omega 4.x?

joseph.olstad’s picture

see this comment: https://www.drupal.org/node/2232467#comment-9119081

and this commit:

http://cgit.drupalcode.org/wetkit_omega/commit/?id=82a19ec43ec216bd219dd...

rather than change the way omega is doing things we ended up changing our tpl.

rohittiwari’s picture

We are not using the wetkit_omega theme? And i am using theme based on

name = Omega
description = <a href="http://drupal.org/project/omega">Omega</a> extends the Omega theme framework with some additional features and makes them availabe to its subthemes. This theme should not be used directly, instead you should create a subtheme based on one of the Omega or Alpha starterkits. Learn more about <a href="http://drupal.org/node/819170">Creating an Omega Subtheme</a> in the <a href="http://drupal.org/node/819164">Omega Handbook</a>.
core = 7.x
engine = phptemplate
screenshot = screenshot.png
version = 3.x
base theme = alpha
steinmb’s picture

Version: 7.x-3.1 » 7.x-3.x-dev