Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit b28793f

Browse files
committed
MAGETWO-67048: Cannot add translate attribute into the di.xml
1 parent 37e86fa commit b28793f

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

dev/tests/integration/testsuite/Magento/Framework/ObjectManager/Config/Reader/DomTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Framework\ObjectManager\Config\Reader;
78

9+
use Magento\Framework\Phrase;
10+
811
/**
912
* Class DomTest @covers \Magento\Framework\ObjectManager\Config\Reader\Dom
1013
*
@@ -63,6 +66,16 @@ protected function setUp()
6366
false
6467
);
6568
$this->_fileResolverMock->expects($this->once())->method('get')->will($this->returnValue($this->_fileList));
69+
70+
/** @var Phrase\Renderer\Composite|\PHPUnit_Framework_MockObject_MockObject $renderer */
71+
$renderer = $this->getMockBuilder(Phrase\Renderer\Composite::class)
72+
->disableOriginalConstructor()
73+
->getMock();
74+
/** check arguments won't be translated for ObjectManager, even if has attribute 'translate'=true. */
75+
$renderer->expects(self::never())
76+
->method('render');
77+
Phrase::setRenderer($renderer);
78+
6679
$this->_mapper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
6780
\Magento\Framework\ObjectManager\Config\Mapper\Dom::class
6881
);

dev/tests/integration/testsuite/Magento/Framework/ObjectManager/_files/config_one.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<argument name="boolZeroParam" xsi:type="boolean">false</argument>
2929
<argument name="intValueParam" xsi:type="number">100500</argument>
3030
<argument name="nullValueParam" xsi:type="null"/>
31-
<argument name="stringPatternParam" xsi:type="string">az-value</argument>
31+
<argument name="stringPatternParam" xsi:type="string" translate="true">az-value</argument>
3232
</arguments>
3333
</type>
3434
</config>

lib/internal/Magento/Framework/App/ObjectManagerFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ protected function createArgumentInterpreter(
225225
$result = new \Magento\Framework\Data\Argument\Interpreter\Composite(
226226
[
227227
'boolean' => new \Magento\Framework\Data\Argument\Interpreter\Boolean($booleanUtils),
228-
'string' => new \Magento\Framework\Data\Argument\Interpreter\StringUtils($booleanUtils),
228+
'string' => new \Magento\Framework\Data\Argument\Interpreter\StringUtils($booleanUtils, false),
229229
'number' => new \Magento\Framework\Data\Argument\Interpreter\Number(),
230230
'null' => new \Magento\Framework\Data\Argument\Interpreter\NullType(),
231231
'object' => new \Magento\Framework\Data\Argument\Interpreter\DataObject($booleanUtils),

lib/internal/Magento/Framework/Data/Argument/Interpreter/StringUtils.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Framework\Data\Argument\Interpreter;
78

89
use Magento\Framework\Data\Argument\InterpreterInterface;
@@ -19,11 +20,24 @@ class StringUtils implements InterpreterInterface
1920
private $booleanUtils;
2021

2122
/**
23+
* Should string utils translate incoming string status.
24+
*
25+
* @var bool
26+
*/
27+
private $translatable;
28+
29+
/**
30+
* StringUtils constructor.
31+
*
2232
* @param BooleanUtils $booleanUtils
33+
* @param bool $translatable
2334
*/
24-
public function __construct(BooleanUtils $booleanUtils)
25-
{
35+
public function __construct(
36+
BooleanUtils $booleanUtils,
37+
$translatable = true
38+
) {
2639
$this->booleanUtils = $booleanUtils;
40+
$this->translatable = $translatable;
2741
}
2842

2943
/**
@@ -38,13 +52,18 @@ public function evaluate(array $data)
3852
if (!is_string($result)) {
3953
throw new \InvalidArgumentException('String value is expected.');
4054
}
41-
$needTranslation = isset($data['translate']) ? $this->booleanUtils->toBoolean($data['translate']) : false;
42-
if ($needTranslation) {
43-
$result = (string)new \Magento\Framework\Phrase($result);
55+
if ($this->translatable) {
56+
$needTranslation = isset($data['translate'])
57+
? $this->booleanUtils->toBoolean($data['translate'])
58+
: false;
59+
if ($needTranslation) {
60+
$result = (string)new \Magento\Framework\Phrase($result);
61+
}
4462
}
4563
} else {
4664
$result = '';
4765
}
66+
4867
return $result;
4968
}
5069
}

0 commit comments

Comments
 (0)