Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Do not load recommended modules on edit or detail pages. #793

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/Traits/Hooks/UseActionAdminControllerSetMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function bootUseActionAdminControllerSetMedia(): void
/**
* Hook actionAdminControllerSetMedia.
*/
public function hookActionAdminControllerSetMedia(): void
public function hookActionAdminControllerSetMedia($params): void
{
if (\Tools::getValue('controller') === 'AdminPsMboModule') {
$this->context->controller->addJs(
Expand All @@ -58,7 +58,7 @@ public function hookActionAdminControllerSetMedia(): void
return $a['order'] === $b['order'] ? 0 : $order;
});
foreach ($this->adminControllerMediaMethods as $setMediaMethod) {
$this->{$setMediaMethod['method']}();
$this->{$setMediaMethod['method']}($params);
}
}

Expand All @@ -84,9 +84,11 @@ protected function addAdminControllerMedia(string $setMediaMethod, int $order =
/**
* Add JS and CSS file
*
* @param array $hookParams
*
* @return void
*/
protected function loadMediaForAdminControllerSetMedia(): void
protected function loadMediaForAdminControllerSetMedia(array $hookParams): void
{
if (in_array(\Tools::getValue('controller'), self::CONTROLLERS_WITH_CDC_SCRIPT)) {
$this->context->controller->addJs('/js/jquery/plugins/growl/jquery.growl.js?v=' . $this->version);
Expand All @@ -103,10 +105,10 @@ protected function loadMediaForAdminControllerSetMedia(): void
// Add it to have all script work on all pages...
$this->context->controller->addJs('/admin-dev/themes/default/js/bundle/default.js?v=' . _PS_VERSION_);
}
$this->loadCdcMedia();
$this->loadCdcMedia($hookParams);
}

private function loadCdcMedia(): void
private function loadCdcMedia(array $hookParams): void
{
$controllerName = \Tools::getValue('controller');
if (!is_string($controllerName)) {
Expand All @@ -118,6 +120,12 @@ private function loadCdcMedia(): void
) {
return;
}
if (
Tab::mayDisplayRecommendedModules($controllerName)
&& $this->isSymfonyContext() && !empty($hookParams['route']) && !str_ends_with($hookParams['route'], '_index')
) {
return;
}

$this->context->controller->addJs($this->getPathUri() . 'views/js/cdc-error-templating.js');
$this->context->controller->addCss($this->getPathUri() . 'views/css/cdc-error-templating.css');
Expand Down
20 changes: 13 additions & 7 deletions src/Traits/Hooks/UseDisplayDashboardTop.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function bootUseDisplayDashboardTop(): void
*
* @throws \Exception
*/
public function hookDisplayDashboardTop(): string
public function hookDisplayDashboardTop($params): string
{
// Check if this page has already been processed by the hook to avoid duplicate content
if ($this->alreadyProcessedPage) {
Expand Down Expand Up @@ -113,7 +113,7 @@ public function hookDisplayDashboardTop(): string

return $shouldDisplayMessageInConfigPage
? $this->displayPushOnConfigurationPage($values['configure'])
: $this->displayRecommendedModules($values['controller'] ?? '');
: $this->displayRecommendedModules($values['controller'] ?? '', $params);
}

/**
Expand Down Expand Up @@ -223,8 +223,12 @@ private function displayFailedApiUser(): string
*
* @throws \Exception
*/
protected function displayRecommendedModules(string $controller): string
protected function displayRecommendedModules(string $controller, array $hookParams): string
{
if ($this->isSymfonyContext() && !empty($hookParams['route']) && !str_ends_with($hookParams['route'], '_index')) {
return '';
}

$recommendedModulesDisplayed = true;

// Ask to modules if recommended modules should be displayed in this context
Expand Down Expand Up @@ -331,15 +335,17 @@ protected function shouldAttachRecommendedModules(string $type): bool
*
* @see UseActionAdminControllerSetMedia
*/
protected function loadMediaForDashboardTop(): void
protected function loadMediaForDashboardTop($hookParams): void
{
// has to be loaded in header to prevent flash of content
$this->context->controller->addJs($this->getPathUri() . 'views/js/recommended-modules.js?v=' . $this->version);

if ($this->isSymfonyContext() && !empty($hookParams['route']) && !str_ends_with($hookParams['route'], '_index')) {
return;
}
if (
$this->shouldAttachRecommendedModules(TabInterface::RECOMMENDED_BUTTON_TYPE)
|| $this->shouldAttachRecommendedModules(TabInterface::RECOMMENDED_AFTER_CONTENT_TYPE)
) {
// has to be loaded in header to prevent flash of content
$this->context->controller->addJs($this->getPathUri() . 'views/js/recommended-modules.js?v=' . $this->version);
$this->context->controller->addCSS($this->getPathUri() . 'views/css/recommended-modules.css');
}
}
Expand Down
Loading