Discovered while debugging #2188661: Extension System, Part II: ExtensionDiscovery

Views uses quite some fancy code to allow both modules and themes to "modify" the view output before and after it is rendered.

"Modify" → "alter"

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Issue tags: +VDC

This has been done without an alter since at least 6.x-2.x, but I have no idea why. Maybe @dawehner knows?

sun’s picture

The last submitted patch, drupal8.views-pre-post-render-alter.0.patch, failed testing.

sun’s picture

since at least 6.x-2.x

I guess the reason is simple: Only D7 added support for alter hooks in themes.

Prior to D7, themes did not participate in drupal_alter().

dawehner’s picture

Mh, so we have all kind of even more hooks:

  • views_pre_build
  • views_pre_view
  • views_pre_execute
  • views_post_execute
  • views_pre_render
  • views_post_render

All of those are mostly used to change the executed view, so we might should consider to mark all of those as alter hooks?

In general you mostly can alter anything in D8 as we use a lot of objects.

On all these hooks in views I would consider views_pre_render as the one which will add new stuff, like new rows etc.

I guess the reason is simple: Only D7 added support for alter hooks in themes.

Still not sure whether we want to keep this functionality to be honest. This causes all kind of dependency problems, as for example the theme system
cannot be loaded lazy due to that.

tim.plunkett’s picture

Aha! That seems like a perfectly logical explanation.

sun’s picture

@dawehner: Interesting.

For the sake of architectural cleanliness, I think that every hook that primarily exists in order to modify previously built/added data should be an alter hook.

Without having any kind of idea what the listed hooks are doing, here are my assumptions:

  1. views_pre_build: Not an alter hook, because nothing was built yet, and unless the idea is that this hook is meant to be hook_views_view_load_alter()?
  2. views_pre_view: Not an alter hook, unless this is meant to be hook_views_view_view_alter() — i.e., to allow to modify the view (render array) of a view of Views module.
  3. views_pre_execute: Most likely a misnomer? I assume this is meant to be hook_views_view_query_alter()? — i.e., alter a views query before it is executed?
  4. views_post_execute: Sounds strange. Perhaps only exists for pre/post consistency?
  5. views_pre_render: This one is definitely the hook_views_view_view_alter() I mentioned above; i.e., modify the already built render array/output structure of a view (operation) of a view of Views module.
  6. views_post_render: Duplicates #post_render of drupal_render()?

Status: Needs review » Needs work

The last submitted patch, 2: drupal8.views-pre-post-render-alter.1.patch, failed testing.

dawehner’s picture

To be honest I can not imagine many usecases which don't alter the view, for non of those hooks.

No hook_views_pre_execute is not hook_views_query_alter ... executing a view is way more than altering the query, actually query is kind of the special case as the query will always depend on your actual query backend you use, though the execution is a general idea.

views_post_execute: Sounds strange. Perhaps only exists for pre/post consistency?

Yes, though there are clear usecases like when you wanna take the result and do something without before it comes to the rendering step.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.