Description
This issue is automatically created based on existing pull request: #32249: Magento_Backend store switcher: Use nowdoc instead of heredoc
Description (*)
The heredoc in Magento/Backend/view/adminhtml/templates/store/switcher.phtml#L203-L216 is not valid, because the embedded JavaScript contains $this
, which happens to be a valid variable name in PHP, too. Consequently, PHP tries to replace its occurrences by the current class object which results in an error. This can be avoided by using nowdoc instead of heredoc, which is the aim of this PR.
In Magento core, the is*using_iframe
flag is never set. As a consequence, the else-branch in [Magento/Backend/view/adminhtml/templates/store/switcher.phtml#L203-L216](https://github.com/magento/magento2/blob/896f0d6/app/code/Magento/Backend/view/adminhtml/templates/store/switcher.phtml#L203-L216] is never called, so the error does not occur in a standard environment. However, we use Amasty's [_Improved Layered Navigation*|https://amasty.com/improved-layered-navigation-for-magento-2.html), which sets this flag to true for one of their backend configurations. The resulting error (in developer mode) looks as follows:
Related Pull Requests
Two years ago, there was #20656 to replace all heredoc by nowdoc, but it was closed.
Fixed Issues (if relevant)
No separate issue created.
Preconditions (*)
Magento 2.4-develop
Steps to reproduce (*)
For reproducing this error, it is not necessary to install Magento or the referenced Amasty extension at all. Simply paste the snippet into a fresh PHP file test.php
:
<?php
$test = <<<script
jQuery('#preview*selected*store').val(scopeId);
jQuery('#preview_form').submit();
jQuery('.store-switcher .dropdown-menu li a').each(function() {
var $this = jQuery(this);
if ($this.data('role') === 'store-view-id' && $this.data('value') == scopeId) {
jQuery('#store-change-button').html($this.text());
}
});
jQuery('#store-change-button').click();
script;
echo $test;
{code}
Calling the script via `php -f test.php` yields a similar error. Changing the first line to `<<<'script'` resolves this issue.
### Actual result
An Exception message appeared
{code}
1 exception(s):
Exception #0 (Exception): Notice: Undefined variable: test in .../app/code/Magento/Backend/view/adminhtml/templates/store/switcher.phtml on line 227
Exception #0 (Exception): Notice: Undefined variable: test in .../app/code/Magento/Backend/view/adminhtml/templates/store/switcher.phtml on line 227
<pre]#1 include() called at [lib/internal/Magento/Framework/View/TemplateEngine/Php.php:71]
#2 Magento\Framework\View\TemplateEngine\Php->render() called at [lib/internal/Magento/Framework/View/Element/Template.php:273]
#3 Magento\Framework\View\Element\Template->fetchView() called at [generated/code/Magento/Backend/Block/Store/Switcher/Interceptor.php:419]
#4 Magento\Backend\Block\Store\Switcher\Interceptor->fetchView() called at [lib/internal/Magento/Framework/View/Element/Template.php:303]
#5 Magento\Framework\View\Element\Template->_toHtml() called at [app/code/Magento/Backend/Block/Template.php:141]
...
#46 Magento\Backend\Model\View\Result\Page\Interceptor->renderResult() called at [lib/internal/Magento/Framework/App/Http.php:120]
#47 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23]
#48 Magento\Framework\App\Http\Interceptor->launch() called at [lib/internal/Magento/Framework/App/Bootstrap.php:264]
#49 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:29]
[/pre>
Expected Result
No errors appear in the Admin panel. The Scope can be changed.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status