Due to #477338: Multiple group: group by more than one field it's not longer really easy to write a custom style plugin as for example you don't have a single point
anymore to override how a view style is rendered.

Comments

dawehner’s picture

StatusFileSize
new2.26 KB

As a beginning we could move the rendering into a new method, but for sure, this is not the only thing we should do.

dawehner’s picture

Title: Improve DX when writing style plugins » Improve DX when writing style plugins by adding a renderSingle function
Status: Active » Needs review

Let's get this single part in, as it still appears and is really useful.

Status: Needs review » Needs work
Issue tags: -VDC

The last submitted patch, drupal-1876964-1.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
Issue tags: +VDC

#1: drupal-1876964-1.patch queued for re-testing.

tim.plunkett’s picture

Status: Needs review » Needs work

This looks okay to me, but I'm not sure why it failed.

dawehner’s picture

Status: Needs work » Needs review
Issue tags: -VDC

#1: drupal-1876964-1.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, drupal-1876964-1.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review

#1: drupal-1876964-1.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +VDC

The last submitted patch, drupal-1876964-1.patch, failed testing.

dawehner’s picture

Seriously, everytime another number of non-reproducable test fails?!

dawehner’s picture

Status: Needs work » Needs review

.

dawehner’s picture

StatusFileSize
new1.35 KB

It simply doesn't make sense to patch both places, as the first one is about grouping and just the second one about the actual output.

dawehner’s picture

#12: drupal-1876964-12.patch queued for re-testing.

tim.plunkett’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

We should probably add a test plugin that uses this. Also, it should likely be protected. Otherwise, I think this is perfect.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new683 bytes
new1.35 KB

Making it protected totally makes sense.

Don't we have general tests for styles already? StyleTest::testStyle() so it seems to be that we just have some internal refactoring here.
What would we test? That the different keys are returned?

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Now that it's protected, its just an internal implementation detail. So no need for dedicated tests.

dawehner’s picture

StatusFileSize
new1.44 KB

Better documentation, suggested by @xjm

xjm’s picture

Issue tags: +Quick fix
webchick’s picture

Status: Reviewed & tested by the community » Needs review

Hm. I don't think I'd ever intuit that a method called "renderSingle" had anything to do with groups or grouping without digging into the PHPDoc. Seems like "renderGroup" or "renderSingleGroup" woud be better?

Although, it's kinda weird we need this distinction. render() doesn't generally care whether it's rendering one of something or a nested several of something. You point it at a key and go.

Can more information be provided on why this is necessary?

tim.plunkett’s picture

StatusFileSize
new68.57 KB

Well, Views render() predates the Render API :(
The grouping bit is about this:
grouping-views.png

Internally, Views always calls render_grouping_sets(), but with only 1 set.

When overriding how a set renders, multiple or not, it will be really useful to have this method split out from the others.

xjm’s picture

Yeah, renderSingleGroup() might be a better method name.

tim.plunkett’s picture

StatusFileSize
new1.06 KB
new1.45 KB

"Renders a single group of a grouped view." => renderSingleGroup()

@webchick++ @xjm++

damiankloip’s picture

Status: Needs review » Reviewed & tested by the community

Yep, that definitely makes sense!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, vdc-1876964-22.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Reviewed & tested by the community

Random failure

dawehner’s picture

I like the new name.

webchick’s picture

Title: Improve DX when writing style plugins by adding a renderSingle function » Change notice: Improve DX when writing style plugins by adding a renderSingle function
Project: Drupal core » Views (for Drupal 7)
Version: 8.x-dev » 8.x-3.x-dev
Component: views.module » Code
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

Thanks, I think that'll be clearer to people.

Committed and pushed to 8.x. Thanks!

I thought this might need a change notice, and Tim agreed, so moving it to the Views queue.

dawehner’s picture

Status: Active » Needs review
xjm’s picture

@dawehner, I think we should put a snippet of an example D7 style plugin and then a D8 one using this method, so that people can see how much better it is in context.

dawehner’s picture

Maybe someone actually finds a good example: All I can find are either incredible complex: calendar, gmap, or do not really something which explains exactly the point of this issue.

xjm’s picture

Well, the D7 plugin would presumably have overridden and copied all of the equivalent of StylePluginBase::render_grouping_sets() just to add a little custom code to the group, right? I have painful memories of doing something along those lines in D6 days. So the "pre-change" version (not necessarily D7 I guess, just without the new method) could just have a clone of render_grouping_sets() with the additional parameter of your example inside?

dawehner’s picture

Non of the contrib examples actually have the bits which show the actual problem. All of them have their own complex stuff, and override the grouping mechanism anyway, so they wouldn't really gain from it.

Well, we could just invent a good example.

xjm’s picture

Right, it doesn't actually need to do anything other than add your '#additional_parameter' => 'foo' I think.

jibran’s picture

Issue tags: +Needs backport to D7

I have updated http://drupal.org/node/1957350 and I also think we need \StylePluginBase::render_grouping_set as well to render single group.

    $theme_functions = views_theme_functions('views_view_grouping', $this->view, $this->view->display_handler->display);
    foreach ($sets as $set) {
      $row = reset($set['rows']);
      // Render as a grouping set.
      if (is_array($row) && isset($row['group'])) {
        $output[] = array(
          //what if I don't want to use theme_views_view_grouping. Something like this :link          
          '#theme' => $theme_functions, 
          '#view' => $this->view,
          '#grouping' => $this->options['grouping'][$level],
          '#grouping_level' => $level,
          '#rows' => $set['rows'],
          '#title' => $set['group'],
        );
      }

:link => http://drupalcode.org/sandbox/jibran/1867222.git/blob/refs/heads/7.x-1.x...

Just talked to @dawehner on IRC we can add above function to views in D7 I will post the patch soon.

jibran’s picture

xjm’s picture

Title: Change notice: Improve DX when writing style plugins by adding a renderSingle function » Improve DX when writing style plugins by adding a renderSingle function
Version: 8.x-3.x-dev » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)
Issue tags: -Needs change record

That looks good! Now on to the backport.

jibran’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.29 KB

D7 patch.

Status: Needs review » Needs work
Issue tags: -Quick fix, -Needs backport to D7, -VDC

The last submitted patch, 1876964-37.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
Issue tags: +Quick fix, +Needs backport to D7, +VDC

#37: 1876964-37.patch queued for re-testing.

xjm’s picture

Title: Improve DX when writing style plugins by adding a renderSingle function » Improve DX when writing style plugins by adding a renderSingleGroup() function

Title was driving me crazy. :)

xjm’s picture

Title: Improve DX when writing style plugins by adding a renderSingleGroup() function » Improve DX when writing style plugins by adding a renderRowGroup() function

And let's respect the followup change too.

jibran’s picture

chris matthews’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs backport to D7 +Needs reroll

The 6 year old patch in #37 to views_plugin_style.inc does not apply to the latest views 7.x-3.x-dev and if still applicable needs to be rerolled.

Checking patch plugins/views_plugin_style.inc...
error: while searching for:
  }

  /**
   * Render the display in this style.
   */
  function render() {

error: patch failed: plugins/views_plugin_style.inc:309
error: plugins/views_plugin_style.inc: patch does not apply
andrew answer’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new1.29 KB

Patch rerolled.