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.
Issue fork lupus_decoupled-3577035
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
Comment #2
adhershmnair commentedComment #4
fagotrue, thank you for the report.
Comment #7
fagoFixed, please report if any issues remain!