Problem/Motivation

Follow up to #1914256: Add all views hooks to hook_hook_info().

All hooks views.api.php in should document in which .inc file they should be placed, see views_hook_info() for the correct locations, either MODULE_NAME.views.inc or MODULE_NAME.views_execution.inc

Steps to reproduce

Proposed resolution

Update all hook documentations in views.api.php to include the correct include file to use. For example do something like:

/**
 * Analyze a view to provide warnings about its configuration.
 *
 * Implementations of this hook should be placed in MODULE_NAME.views.inc.
 *
 * @param \Drupal\views\ViewExecutable $view
 *   The view being executed.
 *
 * @return array
 *   Array of warning messages built by Analyzer::formatMessage to be displayed
 *   to the user following analysis of the view.
 */

Remaining tasks

In this issue

  • Separate the hooks into two documentation groups: one for the runtime hooks (those invoked from ViewExecutable, which go in .views_execution.inc) and the others (which go in .views.inc). Add introductory documentation to each group explaining the differences between the two groups and the purpose of separating them (performance). Reference #1914256: Add all views hooks to hook_hook_info()

Followups needed

  • Document the field hooks separately
  • Deprecate the include file pattern in favor of a different method of on-demand autoloading for the respective hooks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3375847

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:

Comments

Lendude created an issue. See original summary.

Nikolas Haliotis made their first commit to this issue’s fork.

nikolas haliotis’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Needs work

CC failure

nikolas haliotis’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Change matches IS and passes tests now.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
nikolas haliotis’s picture

Status: Needs work » Needs review

Removed implementation details for the field hooks and added the implementation details to the missing hooks.

xjm’s picture

Thanks @quietone, I had also gotten hung up on the field hooks when reviewing this. Here's what I had documented aside from that:

  • query_substitutions: Invoked from src/Plugin/views/query/Sql.php
  • form_substitutions: Invoked from src/Form/ViewsFormMainForm.php
  • Invoked directly from ViewExecutable:
    • views_pre_render
    • views_post_render
    • views_pre_build
    • views_post_build
    • views_pre_view
    • views_pre_execute
    • views_post_execute
  • Also in ViewExecutable:
        // Let modules modify the query just prior to finalizing it.                
        $this->query->alter($this);
    

    ...which gives us views_query_alter.

xjm’s picture

Issue tags: +Needs followup

@Lendude and I also discussed a followup for this. The use of .inc files is archaic, and even in the original issue it was identified that these two magically named include files were bad DX. Their purpose is to avoid loading hundreds/thousands of lines of code that is not needed on a given request, but nowadays we should be able to come up with a better pattern for that with a modern architecture and better DX. To be discussed in the followup. :)

xjm’s picture

Issue summary: View changes
Status: Needs review » Needs work

A thought: Should the runtime hooks and the non-runtime hooks furthermore be placed in different phpdoc groups? Documenting it on the individual hooks is good for when someone just looks up the individual hook, but if we add two defgroups, that will also give us a spot to document the "why" of the two different hook categories from the original issue.

We should also perhaps have a second followup to document the field hooks differently (with their own docs and in their own third group).

Updating the remaining tasks with the above.

nikolas haliotis’s picture

So my understanding is that we want the views.api.php file to be organised like so:

-> a doc block at the start with documentation on the views
-> all the hooks that are relevant
-> a doc block with the documentation for the runtime hooks
-> all the hooks that are relevant
-> a placeholder doc block for the field hooks with a TODO
-> all the field hooks

Also there should be a task about the documentation of the field hooks after this, right?

xjm’s picture

Thanks @Nikolas Haliotis for looking into this. :) Crossposting my remarks from #contribute in Drupal Slack:

I was referring to the phpdoc @defgroup tags: https://www.drupal.org/docs/develop/standards/php/api-documentation-and-...

Currently, there are two @defgroup in views.api.php: A views_overview group and a views_plugins group. I was suggesting maybe creating two new groups, a views_execution_hooks and a views_something_else_hooks (needs a proper name). Each of those groups could have high-level explanations of the differences between the two kinds of hooks and why they get placed where they do.

I do think the added paragraph on the individual hooks is also still useful, so we can leave it there. However, we would remove the changes to the two field hook definitions from the patch, and then have a followup to see if they should be documented in some other way based on how other field hooks are documented elsewhere (possibly an @ingroup or something else, but we don't need to figure it out in this issue, just create a separate issue before it's RTBC).

Hopefully that helps!

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

dww’s picture

Given that hook_hook_info() is gone and we're moving to completely kill off procedural .inc files and move all hooks to OOP, I think this should probably be "outdated" at this point. Any objections?

Thanks/sorry,
-Derek

quietone’s picture

I agree, this is most definitely outdated.

dww’s picture

Status: Needs work » Closed (outdated)

Okay, done.

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

nicxvan’s picture

Just wanted to give a quick note that all closed issues now get credit and everyone here has been granted credit for helping with this, thank you!