Working on the Drupal Dev Days codesprint, I was discussing with dereine that the fact that semantic views stuf went into views core, is going to make jQuery niceness style plugins job much harder in its current form.

The fact that users can configure what markup (or if any markup at all), and what css classes (or if any classes at all) their fields will be printed with, makes up for a ton of combinations, and some not even tackable for jQuery selectors.

So we discussed whether or not style plugins should be able to disable these options, which although it would make our lives easier, I don't think it's a nice way to go. I'm also a user of views, and would like to set my titles with H2's for example.

So, the ideal way would be to either:
1. Have style plugins be able to define default un-removable classes/markup.
2. Be able to set multiple classes for the field wrappers.

I think point 2 would be nice to have in any case, so I went ahead and made a patch for it, find it attached.

Then I can put my own class in my pre_render function like this (for views_accordion):

  /*
   * pre_render() necesary to prevent markup mayhem
   */
  function pre_render() {
    // Find out about the header field options
    $fields = array_values($this->display->display_options['fields']);
    // setup our wrapper class
    // find out  if the user configured its own class
    $header_wrapper_class = $this->view->field[$fields[0]['id']]->options['element_wrapper_class'];
    $header_class = 'views-accordion-header';
    dpm($this->view->field[$fields[0]['id']]->options);
    // set up that with our own class
    $header_wrapper_class = empty($header_wrapper_class) ? $header_class : $header_wrapper_class .' '. $header_class;
    $this->view->field[$fields[0]['id']]->options['element_wrapper_class'] = $header_wrapper_class;
    // make sure we are using a div for markup at least
    if (empty($this->view->field[$fields[0]['id']]->options['element_wrapper_type'])){
      $this->view->field[$fields[0]['id']]->options['element_wrapper_type'] = 'div';
    }
  }

, adding my class to whatever the user had setup there, and making sure we have a div if the user had setup to have no markup at all.
Without this patch, currently I would have to override the user's defined CSS class also, in order to ensure the accordion would work.

I'm sure this approach could be used by other style plugins, and although we'd be overriding the user's options, I don't see a more flexible way to tackle this... opened for suggestions.

In any case, the patch attached still would be nice to have.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Needs review » Fixed

Looks fine.

Commited to the 7.x branch.

Status: Fixed » Closed (fixed)

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

dboulet’s picture

Status: Closed (fixed) » Closed (duplicate)

This probably should have been marked as a duplicate of #1032380: More than one wrapper class.