Problem/Motivation

Original report:

The documentation at http://api.drupal.org says the following about this function's parameters:
string $output: A flat string with the the rendered output of the view.

This is incorrect. $output is a nested array of arrays and classes. If there's some string therein that can be manipulated, I haven't found it.

Additional things to consider:

#11:
Seems like this doc comment hasn't been updated since D7, and now I have no idea where to manipulate the rendered output.

#12:

I think more important is indeed to describe here that you should use the usual render API functionality to change the output, like #post_render.

#21:

During a views autocomplete, $output not a render array, it's an array of render arrays

Proposed resolution

1) Update the description of $output variable;
2) Get rid of legacy documentation that was relevant for D7 version and describe what can be done in this hook;

Remaining tasks

Review and commit.

Issue fork drupal-2793169

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

msypes created an issue. See original summary.

zalak.addweb’s picture

Issue tags: +views
Lendude’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.3.x-dev
Component: Documentation » views.module
Category: Bug report » Task
Issue tags: -views +Documentation

Yeah, it's probably a render array nowadays. Didn't check though. It's the contents of $this->display_handler->output that's being passed.

Moving to the right queue.

Manuel Garcia’s picture

Status: Active » Needs review
FileSize
625 bytes
lomasr’s picture

lomasr’s picture

FileSize
56.77 KB

I applied the patch. It worked for me . Screenshot attached

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ron-g’s picture

When editing a node it pass $output = '' as an empty string instead of an empty array.

TypeError: Argument 2 passed to hook_views_post_render() must be of the type array, string given...

Manuel Garcia’s picture

Thanks @lomasr for checking the patch, but just so you know, the test bot already checks that the patch applies cleanly, so no need to do that manually =)

AaronBauman’s picture

Category: Task » Bug report

Also, perhaps more importantly, this array doesn't actually contain the final renderable output of the view.
e.g. if the view contains a field with "rewrite" enabled, the rewriting has not been done at this point.
And the array doesn't contain the rendered values of fields.

Seems like this doc comment hasn't been updated since D7, and now I have no idea where to manipulate the rendered output.
@Lendude, any particular reason this should not be considered a documentation bug?

dawehner’s picture

I think more important is indeed to describe here that you should use the usual render API functionality to change the output, like #post_render.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quiron’s picture

tea.time’s picture

Reading this incorrect api doc cost me a few hours... :( I was hunting every which way for how to alter the renderable array for the view, wondering why there was no hook provided to do so.

Seeing as now this hook does not operate on the markup string, the hook_views_post_render() naming is confusing next to core's #post_render hooks. But changing the Views hook name, or the point at which it is invoked, would be an api-breaking change. So I'm in favor of the documentation update.

As mentioned in #12, this hook can be implemented to add a #post_render hook into the render array, and use that to operate on the markup string.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

sime’s picture

During a views autocomplete, $output not a render array, it's an array of render arrays.

Lendude’s picture

Category: Bug report » Task

Moving back to task since this still feels like a documentation that needs updating not an actual bug.

Manuel Garcia’s picture

Status: Needs review » Needs work
anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
640 bytes
Abhijith S’s picture

FileSize
81.27 KB

Applied patch #24 and it works fine. The output variable is correctly mentioned in documentation after patch.

after

Abhijith S’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 24: 2793169-24.patch, failed testing. View results

anmolgoyal74’s picture

Status: Needs work » Reviewed & tested by the community

unrelated Failure.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/views.api.php
@@ -844,8 +844,8 @@ function hook_views_pre_render(ViewExecutable $view) {
+ *   A array of renderable array containing the output of the view.

I don't know if this is description is accurate but, if it is, the sentence should be 'An array of renderable arrays containing the output of the view'. Although that has problems too because 'renderable' is in the list of mis-spelled words at core/misc/dictionary.txt.

Pooja Ganjage’s picture

Hi,

Creating a patch as suggested in #29 comment.

Please review the patch.

Thanks.

Pooja Ganjage’s picture

Status: Needs work » Needs review

Matroskeen made their first commit to this issue’s fork.

Matroskeen’s picture

Just trying to help to move some Views issues forward :)

At first, the last patch looked very simple and straightforward, so I wanted to give it RTBC. However, after reviewing the comments I think we should expand the scope a little bit.
As for me, the current documentation is no longer relevant (or at least it looks overcomplicated), so I tried to make it simple.

I can also confirm that remark in comment #21 is correct - the structure can be different and depends on the style plugin (see attached screenshots).
default display
entity reference display
(the 2nd screenshot was taken with "Entity Reference" display enabled)

The merge request is looking for a review.

Matroskeen’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dww’s picture

FWIW, I still think documentation bugs are bugs. "Make the documentation more clear and helpful" would be task. "Fix lies in the documentation" seems like a bug. But I won't override @Lendude as an official Views subsystem maintainer on this. 😉

dww’s picture

Status: Needs review » Needs work

Opened some threads in the MR, back to NW.

Saving credits for some of the folks who've materially contributed so far. Haven't fully processed the history, so that task is incomplete.

Lendude’s picture

Category: Task » Bug report
dww’s picture

Issue tags: +Bug Smash Initiative

Cool, thanks. 😉 in that case, BSI...

Matroskeen’s picture

Status: Needs work » Needs review

Thanks for the review! 2 threads are still open and waiting for review :)

dww’s picture

Status: Needs review » Needs work

Thanks for moving this forward (and the Slack ping to remind me to circle back).

Yup, the 2 unresolved threads look good. But I opened 2 more. Sorry and you're welcome. 😉

Cheers,
-Derek

Matroskeen’s picture

Version: 9.3.x-dev » 9.4.x-dev
Status: Needs work » Needs review

Thanks for looking again. We're down to 1 unresolved thread, which is looking for review. 😉

Lendude’s picture

Status: Needs review » Needs work

Looks good, just one little thing I think we still need to update

Matroskeen’s picture

Status: Needs work » Needs review

Thanks for the review!

Lendude’s picture

Status: Needs review » Reviewed & tested by the community

Looks good now, thanks.

alexpott’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed acd7ac969e1 to 10.0.x and cce6f01fed2 to 9.4.x and 23fc2b7d9ee to 9.3.x. Thanks!

  • alexpott committed acd7ac9 on 10.0.x
    Issue #2793169 by Matroskeen, Manuel Garcia, anmolgoyal74, Pooja Ganjage...

  • alexpott committed cce6f01 on 9.4.x
    Issue #2793169 by Matroskeen, Manuel Garcia, anmolgoyal74, Pooja Ganjage...

  • alexpott committed 23fc2b7 on 9.3.x
    Issue #2793169 by Matroskeen, Manuel Garcia, anmolgoyal74, Pooja Ganjage...

Status: Fixed » Closed (fixed)

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