Skip to content

Commit 6f0e5e5

Browse files
authored
Merge pull request #2846 from magento-trigger/MC-1364
[Trigger] Always Render Magento directives on Magento Storefront
2 parents 08d13a1 + 694ed9d commit 6f0e5e5

File tree

14 files changed

+201
-18
lines changed

14 files changed

+201
-18
lines changed

app/code/Magento/Catalog/Helper/Data.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
3232

3333
const CONFIG_USE_STATIC_URLS = 'cms/wysiwyg/use_static_urls_in_catalog';
3434

35+
/**
36+
* @deprecated
37+
* @see \Magento\Catalog\Helper\Output::isDirectivesExists
38+
*/
3539
const CONFIG_PARSE_URL_DIRECTIVES = 'catalog/frontend/parse_url_directives';
3640

3741
const XML_PATH_DISPLAY_PRODUCT_COUNT = 'catalog/layered_navigation/display_product_count';
@@ -443,6 +447,8 @@ public function isUsingStaticUrlsAllowed()
443447
* Check if the parsing of URL directives is allowed for the catalog
444448
*
445449
* @return bool
450+
* @deprecated
451+
* @see \Magento\Catalog\Helper\Output::isDirectivesExists
446452
*/
447453
public function isUrlDirectivesParsingAllowed()
448454
{
@@ -457,6 +463,7 @@ public function isUrlDirectivesParsingAllowed()
457463
* Retrieve template processor for catalog content
458464
*
459465
* @return \Magento\Framework\Filter\Template
466+
* @throws \Magento\Framework\Exception\LocalizedException
460467
*/
461468
public function getPageTemplateProcessor()
462469
{

app/code/Magento/Catalog/Helper/Output.php

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Helper;
79

810
use Magento\Catalog\Model\Category as ModelCategory;
@@ -45,20 +47,29 @@ class Output extends \Magento\Framework\App\Helper\AbstractHelper
4547
protected $_escaper;
4648

4749
/**
50+
* @var array
51+
*/
52+
private $directivePatterns;
53+
54+
/**
55+
* Output constructor.
4856
* @param \Magento\Framework\App\Helper\Context $context
4957
* @param \Magento\Eav\Model\Config $eavConfig
5058
* @param Data $catalogData
5159
* @param \Magento\Framework\Escaper $escaper
60+
* @param array $directivePatterns
5261
*/
5362
public function __construct(
5463
\Magento\Framework\App\Helper\Context $context,
5564
\Magento\Eav\Model\Config $eavConfig,
5665
Data $catalogData,
57-
\Magento\Framework\Escaper $escaper
66+
\Magento\Framework\Escaper $escaper,
67+
$directivePatterns = []
5868
) {
5969
$this->_eavConfig = $eavConfig;
6070
$this->_catalogData = $catalogData;
6171
$this->_escaper = $escaper;
72+
$this->directivePatterns = $directivePatterns;
6273
parent::__construct($context);
6374
}
6475

@@ -134,6 +145,7 @@ public function process($method, $result, $params)
134145
* @param string $attributeName
135146
* @return string
136147
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
148+
* @throws \Magento\Framework\Exception\LocalizedException
137149
*/
138150
public function productAttribute($product, $attributeHtml, $attributeName)
139151
{
@@ -151,10 +163,12 @@ public function productAttribute($product, $attributeHtml, $attributeName)
151163
$attributeHtml = nl2br($attributeHtml);
152164
}
153165
}
154-
if ($attribute->getIsHtmlAllowedOnFront() && $attribute->getIsWysiwygEnabled()) {
155-
if ($this->_catalogData->isUrlDirectivesParsingAllowed()) {
156-
$attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml);
157-
}
166+
if ($attributeHtml !== null
167+
&& $attribute->getIsHtmlAllowedOnFront()
168+
&& $attribute->getIsWysiwygEnabled()
169+
&& $this->isDirectivesExists($attributeHtml)
170+
) {
171+
$attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml);
158172
}
159173

160174
$attributeHtml = $this->process(
@@ -173,6 +187,7 @@ public function productAttribute($product, $attributeHtml, $attributeName)
173187
* @param string $attributeHtml
174188
* @param string $attributeName
175189
* @return string
190+
* @throws \Magento\Framework\Exception\LocalizedException
176191
*/
177192
public function categoryAttribute($category, $attributeHtml, $attributeName)
178193
{
@@ -185,10 +200,13 @@ public function categoryAttribute($category, $attributeHtml, $attributeName)
185200
) {
186201
$attributeHtml = $this->_escaper->escapeHtml($attributeHtml);
187202
}
188-
if ($attribute->getIsHtmlAllowedOnFront() && $attribute->getIsWysiwygEnabled()) {
189-
if ($this->_catalogData->isUrlDirectivesParsingAllowed()) {
190-
$attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml);
191-
}
203+
if ($attributeHtml !== null
204+
&& $attribute->getIsHtmlAllowedOnFront()
205+
&& $attribute->getIsWysiwygEnabled()
206+
&& $this->isDirectivesExists($attributeHtml)
207+
208+
) {
209+
$attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml);
192210
}
193211
$attributeHtml = $this->process(
194212
'categoryAttribute',
@@ -197,4 +215,22 @@ public function categoryAttribute($category, $attributeHtml, $attributeName)
197215
);
198216
return $attributeHtml;
199217
}
218+
219+
/**
220+
* Check if string has directives
221+
*
222+
* @param string $attributeHtml
223+
* @return bool
224+
*/
225+
public function isDirectivesExists($attributeHtml)
226+
{
227+
$matches = false;
228+
foreach ($this->directivePatterns as $pattern) {
229+
if (preg_match($pattern, $attributeHtml)) {
230+
$matches = true;
231+
break;
232+
}
233+
}
234+
return $matches;
235+
}
200236
}

app/code/Magento/Catalog/Setup/Patch/Data/DisallowUsingHtmlForProductName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
6+
declare(strict_types=1);
77
namespace Magento\Catalog\Setup\Patch\Data;
88

99
use Magento\Catalog\Setup\CategorySetupFactory;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
namespace Magento\Catalog\Setup\Patch\Data;
8+
9+
use Magento\Framework\Setup\ModuleDataSetupInterface;
10+
use Magento\Framework\Setup\Patch\DataPatchInterface;
11+
12+
/**
13+
* Class EnableDirectiveParsing
14+
* @package Magento\Catalog\Setup\Patch
15+
*/
16+
class EnableDirectiveParsing implements DataPatchInterface
17+
{
18+
/**
19+
* @var ModuleDataSetupInterface
20+
*/
21+
private $moduleDataSetup;
22+
23+
/**
24+
* PatchInitial constructor.
25+
* @param ModuleDataSetupInterface $moduleDataSetup
26+
*/
27+
public function __construct(
28+
ModuleDataSetupInterface $moduleDataSetup
29+
) {
30+
$this->moduleDataSetup = $moduleDataSetup;
31+
}
32+
33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function apply()
37+
{
38+
$configTable = $this->moduleDataSetup->getTable('core_config_data');
39+
$select = $this->moduleDataSetup->getConnection()->select()
40+
->from($configTable)
41+
->where('path = ?', 'catalog/frontend/parse_url_directives');
42+
$config = $this->moduleDataSetup->getConnection()->fetchAll($select);
43+
if (!empty($config)) {
44+
$this->moduleDataSetup->getConnection()->update(
45+
$configTable,
46+
['value' => '1'],
47+
['path = ?' => 'catalog/frontend/parse_url_directives', 'value IN (?)' => '0']
48+
);
49+
}
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
public static function getDependencies()
56+
{
57+
return [];
58+
}
59+
60+
/**
61+
* {@inheritdoc}
62+
*/
63+
public function getAliases()
64+
{
65+
return [];
66+
}
67+
}

app/code/Magento/Catalog/Test/Mftf/Section/StorefrontProductInfoDetailsSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
1111
<section name="StorefrontProductInfoDetailsSection">
1212
<element name="productNameForReview" type="text" selector=".legend.review-legend>strong" />
13+
<element name="detailsTab" type="button" selector="#tab-label-description-title" />
1314
</section>
1415
</sections>

app/code/Magento/Catalog/etc/adminhtml/system.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@
9292
<comment>Whether to show "All" option in the "Show X Per Page" dropdown</comment>
9393
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
9494
</field>
95-
<field id="parse_url_directives" translate="label comment" type="select" sortOrder="200" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
96-
<label>Allow Dynamic Media URLs</label>
97-
<comment>E.g. {{media url="path/to/image.jpg"}} {{skin url="path/to/picture.gif"}}. Dynamic directives parsing impacts catalog performance.</comment>
98-
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
99-
</field>
10095
</group>
10196
<group id="placeholder" translate="label" sortOrder="300" showInDefault="1" showInWebsite="1" showInStore="1">
10297
<label>Product Image Placeholders</label>

app/code/Magento/Catalog/etc/di.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,17 @@
173173
</type>
174174
<type name="Magento\Catalog\Helper\Data">
175175
<arguments>
176-
<argument name="templateFilterModel" xsi:type="string">Magento\Catalog\Model\Template\Filter</argument>
176+
<argument name="templateFilterModel" xsi:type="string">Magento\Widget\Model\Template\Filter</argument>
177177
<argument name="catalogSession" xsi:type="object">Magento\Catalog\Model\Session\Proxy</argument>
178178
</arguments>
179179
</type>
180+
<type name="Magento\Catalog\Helper\Output">
181+
<arguments>
182+
<argument name="directivePatterns" xsi:type="array">
183+
<item name="construct" xsi:type="const">\Magento\Framework\Filter\Template::CONSTRUCTION_PATTERN</item>
184+
</argument>
185+
</arguments>
186+
</type>
180187
<type name="Magento\Catalog\Model\Config\Source\GridPerPage">
181188
<arguments>
182189
<argument name="perPageValues" xsi:type="string">9,15,30</argument>

app/code/Magento/Catalog/i18n/en_US.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,6 @@ Comma-separated.,Comma-separated.
658658
"Product Listing Sort by","Product Listing Sort by"
659659
"Allow All Products per Page","Allow All Products per Page"
660660
"Whether to show ""All"" option in the ""Show X Per Page"" dropdown","Whether to show ""All"" option in the ""Show X Per Page"" dropdown"
661-
"Allow Dynamic Media URLs","Allow Dynamic Media URLs"
662661
"E.g. {{media url=""path/to/image.jpg""}} {{skin url=""path/to/picture.gif""}}. Dynamic directives parsing impacts catalog performance.","E.g. {{media url=""path/to/image.jpg""}} {{skin url=""path/to/picture.gif""}}. Dynamic directives parsing impacts catalog performance."
663662
"Product Image Placeholders","Product Image Placeholders"
664663
"Search Engine Optimization","Search Engine Optimization"

app/code/Magento/Cms/Test/Mftf/Data/CmsPageData.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<data key="identifier" unique="suffix">testpage-</data>
2828
</entity>
2929
<entity name="simpleCmsPage" type="cms_page">
30-
<data key="title">Test CMS Page</data>
30+
<data key="title" unique="suffix">Test CMS Page</data>
3131
<data key="content_heading">Test Content Heading</data>
3232
<data key="content">Sample page content. Yada yada yada.</data>
3333
<data key="identifier" unique="suffix">test-page-</data>

app/code/Magento/Cms/Test/Mftf/Test/AdminAddWidgetToWYSIWYGWithRecentlyComparedProductsTypeTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<description value="Admin should be able to create a CMS page with widget type: Recently Compared Products"/>
1818
<severity value="CRITICAL"/>
1919
<testCaseId value="MAGETWO-83792"/>
20+
<!--Skip test due to MC-1284-->
21+
<group value="skip"/>
2022
</annotations>
2123
<!--Main test-->
2224
<before>

0 commit comments

Comments
 (0)