Problem/Motivation

In CustomElementsPage::render(), the call to moduleHandler()->alter() passes an undefined local variable $view as the second context parameter. The correct variable is $this->view.

$this->view is used correctly on lines 91 and 94 of the same method, but line 95 passes the bare $view which is never defined in the method scope.

File: modules/lupus_decoupled_views/src/Plugin/views/display/CustomElementsPage.php, line 95:

$this->moduleHandler()->alter('lupus_decoupled_views_page_alter', $custom_element, $view, $render);

This causes a PHP warning (Undefined variable $view) and any alter hook implementation that tries to use the $view context parameter will receive NULL instead of the ViewExecutable object.

Also Wrong alter hook type lupus_decoupled_views_page_alter (should be lupus_decoupled_views_page) - causes the documented hook to never fire

Steps to reproduce

1. Install lupus_decoupled_views module (version 1.4.1).
2. Create a Views display using the "Custom Elements Page" display plugin.
3. Implement hook_lupus_decoupled_views_page_alter() in a custom module and attempt to use the $view context parameter:

function mymodule_lupus_decoupled_views_page_alter(&$custom_element, &$view, &$render) {
  $view_id = $view->id(); // TypeError: Call to member function on null.
}

4. Visit the page served by the Custom Elements Page display.
5. A PHP warning is generated and any code relying on $view will fail.

Note: Modules that only use $custom_element in their alter hook are unaffected.

Proposed resolution

One-line fix - replace $view with $this->view:

- $this->moduleHandler()->alter('lupus_decoupled_views_page_alter', $custom_element, $view, $render);
+ $this->moduleHandler()->alter('lupus_decoupled_views_page_alter', $custom_element, $this->view, $render);

Additionally, lupus_decoupled_views.api.php should be updated to document the full hook signature including the $view and $render context parameters.

Remaining tasks

- Review and commit the one-line fix.
- Update lupus_decoupled_views.api.php hook documentation to include full parameter signature.

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

adhershmnair created an issue. See original summary.

adhershmnair’s picture

Issue summary: View changes

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

fago’s picture

Version: 1.4.1 » 1.x-dev
Status: Active » Needs review

true, thank you for the report.

  • fago committed 104b4e85 on 1.x
    fix: #3577035 Fix hook_lupus_decoupled_views_page_alter() to be...
fago’s picture

Status: Needs review » Fixed

Fixed, please report if any issues remain!

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.

Status: Fixed » Closed (fixed)

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