Skip to content

Commit

Permalink
add hook
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-rolland committed Aug 1, 2024
1 parent fd52627 commit 8a4b010
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions classes/controller/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,31 +541,40 @@ protected function assignGeneralPurposeVariables()
$cart = new Cart();
}

$templateVars = [
'cart' => $this->cart_presenter->present($cart),
'currency' => $this->getTemplateVarCurrency(),
'customer' => $this->getTemplateVarCustomer(),
'country' => $this->objectPresenter->present($this->context->country),
'language' => $this->objectPresenter->present($this->context->language),
'page' => $this->getTemplateVarPage(),
'shop' => $this->getTemplateVarShop(),
'core_js_public_path' => $this->getCoreJsPublicPath(),
'urls' => $this->getTemplateVarUrls(),
'configuration' => $this->getTemplateVarConfiguration(),
'field_required' => $this->context->customer->validateFieldsRequiredDatabase(),
'breadcrumb' => $this->getBreadcrumb(),
'link' => $this->context->link,
'time' => time(),
'static_token' => Tools::getToken(false),
'token' => Tools::getToken(),
'debug' => _PS_MODE_DEV_,
];
$templateVars = [];

Hook::exec(
'actionFrontControllerSetVariablesBefore',
[
'templateVars' => &$templateVars,
'cart' => $cart,
],
);

$templateVars['cart'] = $templateVars['cart'] ?? $this->cart_presenter->present($cart);
$templateVars['currency'] = $templateVars['currency'] ?? $this->getTemplateVarCurrency();
$templateVars['customer'] = $templateVars['customer'] ?? $this->getTemplateVarCustomer();
$templateVars['country'] = $templateVars['country'] ?? $this->objectPresenter->present($this->context->country);
$templateVars['language'] = $templateVars['language'] ?? $this->objectPresenter->present($this->context->language);
$templateVars['page'] = $templateVars['page'] ?? $this->getTemplateVarPage();
$templateVars['shop'] = $templateVars['shop'] ?? $this->getTemplateVarShop();
$templateVars['core_js_public_path'] = $templateVars['core_js_public_path'] ?? $this->getCoreJsPublicPath();
$templateVars['urls'] = $templateVars['urls'] ?? $this->getTemplateVarUrls();
$templateVars['configuration'] = $templateVars['configuration'] ?? $this->getTemplateVarConfiguration();
$templateVars['field_required'] = $templateVars['field_required'] ?? $this->context->customer->validateFieldsRequiredDatabase();
$templateVars['breadcrumb'] = $templateVars['breadcrumb'] ?? $this->getBreadcrumb();
$templateVars['link'] = $templateVars['link'] ?? $this->context->link;
$templateVars['time'] = $templateVars['time'] ?? time();
$templateVars['static_token'] = $templateVars['static_token'] ?? Tools::getToken(false);
$templateVars['token'] = $templateVars['token'] ?? Tools::getToken();
$templateVars['debug'] = $templateVars['debug'] ?? _PS_MODE_DEV_;

// An array [module_name => module_output] will be returned
$modulesVariables = Hook::exec(
'actionFrontControllerSetVariables',
[
'templateVars' => &$templateVars,
'cart' => $cart,
],
null,
true
Expand Down

0 comments on commit 8a4b010

Please sign in to comment.