Problem/Motivation

QuickTabsInstance::getRenderArray() calls hook_quicktabs_instance_alter() before rendering (line 222), but QuickTabsController::ajaxContent() loads the
entity and renders directly without calling it (lines 62-65). Modules that use the alter to set view arguments or modify tab configuration have their changes ignored on AJAX-loaded tabs.

Steps to reproduce

  1. Create a QuickTabs instance with AJAX enabled and a Views tab that uses a contextual filter.
  2. Implement hook_quicktabs_instance_alter() to set the view argument dynamically.
  3. Load the page — the default tab renders correctly (alter fires via getRenderArray()).
  4. Click a non-default tab — the AJAX-loaded tab ignores the alter and renders with no argument.

Proposed resolution

Inject ModuleHandlerInterface into QuickTabsController and call the alter before reading configuration data in ajaxContent():

$this->moduleHandler->alter('quicktabs_instance', $qt);                                                                                                                                 
  $configuration_data = $qt->getConfigurationData();

API changes

None. Existing hook_quicktabs_instance_alter() will now fire on AJAX tab loads as well as server-rendered loads.

Issue fork quicktabs-3606674

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

loze created an issue. See original summary.

loze’s picture

Issue summary: View changes

loze’s picture

Status: Active » Needs review

This MR adds $this->moduleHandler()->alter('quicktabs_instance', $qt) before $qt->getConfigurationData() in the controller.

Also added a test module quicktabs_alter_test which implements the alter hook and tracks calls via State API.
Three kernel tests verify: the alter fires on server render, the alter fires on the AJAX path, and the altered configuration is reflected in the rendered output.

loze’s picture

What do you think of this new proposed approach?

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

joelpittet’s picture

Thanks for your help on this again @loze. I have merged it in!

I am going to take a quick look at that a11y issue in the queue but after that I might cut another release, just a bit worried how minor releases look on the project page.

joelpittet’s picture

Status: Needs review » Fixed

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.

  • joelpittet committed 2cbbbfb3 on 4.0.x authored by loze
    fix: #3606674 hook_quicktabs_instance_alter() not invoked on AJAX tab...
loze’s picture

Thank you too for all the work and pushing these through!