Skip to content

Commit bbdbc48

Browse files
🔃 [EngCom] Public Pull Requests - 2.1-develop
Accepted Public Pull Requests: - #14349: Backport of PR-10445 for Magento 2.1: Fix JS translation search (by @hostep) - #14198: [Backport] Can't cancel removal of a block or container in layout by setting remove attribute value to false (by @quisse) Fixed GitHub Issues: - #7403: JS Translation Regex leads to unexpected results and untranslatable strings (reported by @thlassche) has been fixed in #14349 by @hostep in 2.1-develop branch Related commits: 1. 893e4f2 - #1931: Can't cancel removal of a block or container in layout by setting remove attribute value to false (reported by @thomasnordkvist) has been fixed in #14198 by @quisse in 2.1-develop branch Related commits: 1. 44746e0 2. 2423fac
2 parents 49f4330 + 199b7af commit bbdbc48

File tree

8 files changed

+63
-14
lines changed

8 files changed

+63
-14
lines changed

app/code/Magento/Translation/Model/Js/DataProvider.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2013-2018 Magento, Inc. All rights reserved.
3+
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

@@ -124,12 +124,13 @@ protected function getPhrases($content)
124124
{
125125
$phrases = [];
126126
foreach ($this->config->getPatterns() as $pattern) {
127-
$result = preg_match_all($pattern, $content, $matches);
127+
$concatenatedContent = preg_replace('~(["\'])\s*?\+\s*?\1~', '', $content);
128+
$result = preg_match_all($pattern, $concatenatedContent, $matches);
128129

129130
if ($result) {
130131
if (isset($matches[2])) {
131132
foreach ($matches[2] as $match) {
132-
$phrases[] = str_replace('\\\'', '\'', $match);
133+
$phrases[] = str_replace(["\'", '\"'], ["'", '"'], $match);
133134
}
134135
}
135136
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
<argument name="patterns" xsi:type="array">
6060
<item name="i18n_translation" xsi:type="string"><![CDATA[~i18n\:\s*(["'])(.*?)(?<!\\)\1~]]></item>
6161
<item name="translate_wrapping" xsi:type="string"><![CDATA[~translate\=("')([^\'].*?)\'\"~]]></item>
62-
<item name="mage_translation_widget" xsi:type="string">~\$\.mage\.__\((?s)[^'"]*?(['"])(.+?)\1(?s).*?\)~</item>
63-
<item name="mage_translation_static" xsi:type="string">~\$t\((?s)[^'"]*?(["'])(.+?)\1(?s).*?\)~</item>
62+
<item name="mage_translation_widget" xsi:type="string"><![CDATA[~(?:\$|jQuery)\.mage\.__\((?s)[^'"]*?(['"])(.+?)(?<!\\)\1(?s).*?\)~]]></item>
63+
<item name="mage_translation_static" xsi:type="string"><![CDATA[~\$t\((?s)[^'"]*?(["'])(.+?)\1(?s).*?\)~]]></item>
6464
</argument>
6565
</arguments>
6666
</type>

dev/tests/integration/testsuite/Magento/Framework/View/LayoutDirectivesTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ public function testRemove()
198198
$this->assertTrue($layout->isBlock('child_block2'));
199199
}
200200

201+
/**
202+
* @magentoAppIsolation enabled
203+
*/
204+
public function testRemoveCancellation()
205+
{
206+
$layout = $this->_getLayoutModel('remove_cancellation.xml');
207+
$this->assertTrue($layout->isContainer('container1'));
208+
$this->assertTrue($layout->isBlock('child_block1'));
209+
$this->assertTrue($layout->isBlock('no_name2'));
210+
$this->assertFalse($layout->getBlock('not_exist'));
211+
}
212+
201213
/**
202214
* @magentoAppIsolation enabled
203215
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<layout>
9+
<container name="container1" label="Container 1">
10+
<block class="Magento\Framework\View\Element\Text" name="no_name2"/>
11+
</container>
12+
<referenceContainer name="container1" remove="true"/>
13+
<referenceBlock name="child_block1" remove="true"/>
14+
<block class="Magento\Framework\View\Element\Text" name="block_container" as="block.container">
15+
<block class="Magento\Framework\View\Element\Text" name="child_block1"/>
16+
<block class="Magento\Framework\View\Element\Text" name="child_block2"/>
17+
</block>
18+
<referenceContainer name="not_exist" remove="false"/>
19+
<referenceContainer name="container1" remove="false"/>
20+
<referenceBlock name="child_block1" remove="false"/>
21+
</layout>

lib/internal/Magento/Framework/View/Layout/Reader/Block.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,15 @@ protected function scheduleReference(
207207
$elementRemove = filter_var($currentElement->getAttribute('remove'), FILTER_VALIDATE_BOOLEAN);
208208
if ($elementRemove) {
209209
$scheduledStructure->setElementToRemoveList($elementName);
210-
} else {
211-
$data = $scheduledStructure->getStructureElementData($elementName, []);
212-
$data['attributes'] = $this->mergeBlockAttributes($data, $currentElement);
213-
$this->updateScheduledData($currentElement, $data);
214-
$this->evaluateArguments($currentElement, $data);
215-
$scheduledStructure->setStructureElementData($elementName, $data);
210+
return;
211+
} elseif ($currentElement->getAttribute('remove')) {
212+
$scheduledStructure->unsetElementFromListToRemove($elementName);
216213
}
214+
$data = $scheduledStructure->getStructureElementData($elementName, []);
215+
$data['attributes'] = $this->mergeBlockAttributes($data, $currentElement);
216+
$this->updateScheduledData($currentElement, $data);
217+
$this->evaluateArguments($currentElement, $data);
218+
$scheduledStructure->setStructureElementData($elementName, $data);
217219
}
218220

219221
/**

lib/internal/Magento/Framework/View/Layout/Reader/Container.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,12 @@ protected function containerReference(
141141
) {
142142
$containerName = $currentElement->getAttribute('name');
143143
$containerRemove = filter_var($currentElement->getAttribute('remove'), FILTER_VALIDATE_BOOLEAN);
144-
145144
if ($containerRemove) {
146145
$scheduledStructure->setElementToRemoveList($containerName);
147-
} else {
148-
$this->mergeContainerAttributes($scheduledStructure, $currentElement);
146+
return;
147+
} elseif ($currentElement->getAttribute('remove')) {
148+
$scheduledStructure->unsetElementFromListToRemove($containerName);
149149
}
150+
$this->mergeContainerAttributes($scheduledStructure, $currentElement);
150151
}
151152
}

lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/BlockTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ public function testProcessReference(
188188
$setCondition,
189189
$setRemoveCondition
190190
) {
191+
if ($literal == 'referenceBlock' && $remove == 'false') {
192+
$this->scheduledStructure->expects($this->once())
193+
->method('unsetElementFromListToRemove')
194+
->with($literal);
195+
}
196+
191197
$this->context->expects($this->once())->method('getScheduledStructure')
192198
->will($this->returnValue($this->scheduledStructure));
193199

lib/internal/Magento/Framework/View/Test/Unit/Layout/Reader/ContainerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ public function testProcess(
102102
->with($contextMock, $elementCurrent)
103103
->willReturnSelf();
104104

105+
if ($elementCurrent->getAttribute('remove') == 'false') {
106+
$scheduledStructureMock->expects($this->once())
107+
->method('unsetElementFromListToRemove')
108+
->with($elementCurrent->getAttribute('name'));
109+
}
110+
105111
$this->container->interpret($contextMock, $elementCurrent);
106112
}
107113

0 commit comments

Comments
 (0)