Skip to content

Commit c8fc7de

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-54790' into BUGS
2 parents 80f3467 + bdf2d49 commit c8fc7de

File tree

12 files changed

+308
-31
lines changed

12 files changed

+308
-31
lines changed

app/code/Magento/Backend/Block/Page/System/Config/Robots/Reset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/**
1414
* "Reset to Defaults" button renderer
1515
*
16+
* @deprecated
1617
* @author Magento Core Team <core@magentocommerce.com>
1718
*/
1819
class Reset extends \Magento\Config\Block\System\Config\Form\Field

app/code/Magento/Backend/Test/Unit/Block/Page/System/Config/Robots/ResetTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
*/
1010
namespace Magento\Backend\Test\Unit\Block\Page\System\Config\Robots;
1111

12+
/**
13+
* Class ResetTest
14+
* @deprecated
15+
* @package Magento\Backend\Test\Unit\Block\Page\System\Config\Robots
16+
*/
1217
class ResetTest extends \PHPUnit_Framework_TestCase
1318
{
1419
/**

app/code/Magento/Config/view/adminhtml/templates/page/system/config/robots/reset.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// @codingStandardsIgnoreFile
88

99
/**
10+
* @deprecated
1011
* @var $block \Magento\Backend\Block\Page\System\Config\Robots\Reset
1112
* @var $jsonHelper \Magento\Framework\Json\Helper\Data
1213
*/
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Test\Unit\Ui\Component\Design\Config\SearchRobots;
7+
8+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
9+
use Magento\Framework\View\Element\UiComponentFactory;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Theme\Ui\Component\Design\Config\SearchRobots\ResetButton;
12+
use Magento\Framework\View\Element\UiComponent\Processor;
13+
use Magento\Ui\Component\Form\Field;
14+
15+
class ResetButtonTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var \PHPUnit_Framework_MockObject_MockObject | ContextInterface
19+
*/
20+
private $contextMock;
21+
22+
/**
23+
* @var \PHPUnit_Framework_MockObject_MockObject | UiComponentFactory
24+
*/
25+
private $componentFactoryMock;
26+
27+
/**
28+
* @var \PHPUnit_Framework_MockObject_MockObject | ScopeConfigInterface
29+
*/
30+
private $scopeConfigMock;
31+
32+
/**
33+
* @var \PHPUnit_Framework_MockObject_MockObject |
34+
*/
35+
private $processorMock;
36+
37+
/**
38+
* @var \PHPUnit_Framework_MockObject_MockObject |
39+
*/
40+
private $wrappingComponentMock;
41+
42+
/**
43+
* @var ResetButton
44+
*/
45+
private $resetButton;
46+
47+
public function setUp()
48+
{
49+
$this->contextMock = $this->getMockBuilder(ContextInterface::class)
50+
->disableOriginalConstructor()
51+
->getMock();
52+
$this->componentFactoryMock = $this->getMockBuilder(UiComponentFactory::class)
53+
->disableOriginalConstructor()
54+
->getMock();
55+
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
56+
->disableOriginalConstructor()
57+
->getMock();
58+
$this->processorMock = $this->getMockBuilder(Processor::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
$this->contextMock->expects($this->atLeastOnce())
62+
->method("getProcessor")
63+
->willReturn($this->processorMock);
64+
$this->wrappingComponentMock = $this->getMockBuilder(Field::class)
65+
->disableOriginalConstructor()
66+
->getMock();
67+
68+
$this->resetButton = new ResetButton(
69+
$this->contextMock,
70+
$this->componentFactoryMock,
71+
[],
72+
[
73+
'config' => [
74+
'formElement' => 'button'
75+
]
76+
],
77+
$this->scopeConfigMock
78+
);
79+
}
80+
81+
public function testPrepare()
82+
{
83+
$robotsContent = "Content";
84+
85+
$this->componentFactoryMock->expects($this->once())
86+
->method("create")
87+
->willReturn($this->wrappingComponentMock);
88+
$this->wrappingComponentMock->expects($this->once())
89+
->method("getContext")
90+
->willReturn($this->contextMock);
91+
$this->scopeConfigMock->expects($this->once())
92+
->method("getValue")
93+
->willReturn($robotsContent);
94+
95+
$this->resetButton->prepare();
96+
$actions = $this->resetButton->getData("config/actions");
97+
$this->assertEquals(json_encode($robotsContent), $actions[0]["params"][0]);
98+
}
99+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Ui\Component\Design\Config\SearchRobots;
7+
8+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
9+
use Magento\Framework\View\Element\UiComponentFactory;
10+
use Magento\Ui\Component\Form\Field;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
13+
class ResetButton extends Field
14+
{
15+
/**
16+
* Page robots default instructions
17+
*/
18+
const XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS = 'design/search_engine_robots/default_custom_instructions';
19+
20+
/** @var ScopeConfigInterface */
21+
private $scopeConfig;
22+
23+
/**
24+
* ResetButton constructor.
25+
* @param ContextInterface $context
26+
* @param UiComponentFactory $uiComponentFactory
27+
* @param array|\Magento\Framework\View\Element\UiComponentInterface[] $components
28+
* @param array $data
29+
* @param ScopeConfigInterface $scopeConfig
30+
*/
31+
public function __construct(
32+
ContextInterface $context,
33+
UiComponentFactory $uiComponentFactory,
34+
$components,
35+
array $data,
36+
ScopeConfigInterface $scopeConfig
37+
) {
38+
$this->scopeConfig = $scopeConfig;
39+
parent::__construct($context, $uiComponentFactory, $components, $data);
40+
}
41+
42+
/**
43+
* Get robots.txt custom instruction default value
44+
*
45+
* @return string
46+
*/
47+
private function getRobotsDefaultCustomInstructions()
48+
{
49+
return trim((string)$this->scopeConfig->getValue(
50+
self::XML_PATH_ROBOTS_DEFAULT_CUSTOM_INSTRUCTIONS, ScopeConfigInterface::SCOPE_TYPE_DEFAULT
51+
));
52+
}
53+
54+
/**
55+
* Add js listener to reset button
56+
*
57+
* @throws \Magento\Framework\Exception\LocalizedException
58+
*/
59+
public function prepare()
60+
{
61+
parent::prepare();
62+
63+
$this->_data['config']['actions'] = [
64+
[
65+
'actionName' => 'reset',
66+
'targetName' => '${ $.name }',
67+
'params' => [
68+
json_encode($this->getRobotsDefaultCustomInstructions())
69+
]
70+
]
71+
];
72+
}
73+
}

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@
211211
<item name="path" xsi:type="string">design/footer/absolute_footer</item>
212212
<item name="fieldset" xsi:type="string">other_settings/footer</item>
213213
</item>
214+
<item name="default_robots" xsi:type="array">
215+
<item name="path" xsi:type="string">design/search_engine_robots/default_robots</item>
216+
<item name="fieldset" xsi:type="string">other_settings/search_engine_robots</item>
217+
</item>
218+
<item name="custom_instructions" xsi:type="array">
219+
<item name="path" xsi:type="string">design/search_engine_robots/custom_instructions</item>
220+
<item name="backend_model" xsi:type="string">Magento\Config\Model\Config\Backend\Admin\Robots</item>
221+
<item name="fieldset" xsi:type="string">other_settings/search_engine_robots</item>
222+
</item>
214223
</argument>
215224
</arguments>
216225
</type>

app/code/Magento/Theme/view/adminhtml/ui_component/design_config_form.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,5 +271,49 @@
271271
</argument>
272272
</field>
273273
</fieldset>
274+
<fieldset name="search_engine_robots">
275+
<argument name="data" xsi:type="array">
276+
<item name="config" xsi:type="array">
277+
<item name="label" xsi:type="string">Search Engine Robots</item>
278+
<item name="sortOrder" xsi:type="string">120</item>
279+
<item name="collapsible" xsi:type="boolean">true</item>
280+
<item name="level" xsi:type="number">1</item>
281+
</item>
282+
</argument>
283+
<field name="default_robots">
284+
<argument name="data" xsi:type="array">
285+
<item name="options" xsi:type="object">Magento\Config\Model\Config\Source\Design\Robots</item>
286+
<item name="config" xsi:type="array">
287+
<item name="label" xsi:type="string" translate="true">Default Robots</item>
288+
<item name="dataType" xsi:type="string">text</item>
289+
<item name="formElement" xsi:type="string">select</item>
290+
<item name="dataScope" xsi:type="string">default_robots</item>
291+
<item name="notice" xsi:type="string" translate="true">This will be included before head closing tag in page HTML.</item>
292+
</item>
293+
</argument>
294+
</field>
295+
<field name="custom_instructions">
296+
<argument name="data" xsi:type="array">
297+
<item name="config" xsi:type="array">
298+
<item name="label" xsi:type="string" translate="true">Edit custom instruction of robots.txt File</item>
299+
<item name="dataType" xsi:type="string">text</item>
300+
<item name="formElement" xsi:type="string">textarea</item>
301+
<item name="dataScope" xsi:type="string">custom_instructions</item>
302+
</item>
303+
</argument>
304+
</field>
305+
<field name="reset_to_defaults" class="Magento\Theme\Ui\Component\Design\Config\SearchRobots\ResetButton">
306+
<argument name="data" xsi:type="array">
307+
<item name="config" xsi:type="array">
308+
<item name="title" xsi:type="string">Reset To Defaults</item>
309+
<item name="formElement" xsi:type="string">button</item>
310+
<item name="dataScope" xsi:type="string">reset_to_defaults</item>
311+
<item name="component" xsi:type="string">Magento_Theme/js/form/component/robots-reset-button</item>
312+
<item name="template" xsi:type="string">Magento_Theme/form/button-field</item>
313+
<item name="notice" xsi:type="string" translate="true">This action will delete your custom instructions and reset robots.txt file to system's default settings.</item>
314+
</item>
315+
</argument>
316+
</field>
317+
</fieldset>
274318
</fieldset>
275319
</form>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'Magento_Ui/js/form/components/button',
8+
'uiRegistry'
9+
], function (Button, registry) {
10+
'use strict';
11+
12+
return Button.extend({
13+
defaults: {
14+
customInstructionField: '${ $.parentName }.custom_instructions',
15+
label: '',
16+
buttonTpl: 'Magento_Theme/form/element/button'
17+
},
18+
19+
/**
20+
* @private
21+
* @param {String} json
22+
* @return {String}
23+
*/
24+
_parseJson: function (json) {
25+
return JSON.parse(json);
26+
},
27+
28+
/**
29+
* @param {String} defaultRobotsTxt
30+
*/
31+
reset: function (defaultRobotsTxt) {
32+
var customInstructions = registry.get(this.customInstructionField);
33+
34+
if (customInstructions) {
35+
customInstructions.set('value', this._parseJson(defaultRobotsTxt));
36+
}
37+
}
38+
});
39+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<div class="admin__field"
8+
visible="visible"
9+
css="$data.additionalClasses"
10+
attr="'data-index': index">
11+
<label class="admin__field-label">
12+
<span text="label"/>
13+
</label>
14+
15+
<div class="admin__field-control"
16+
css="'_with-tooltip': $data.tooltip">
17+
<render args="tooltipTpl" if="$data.tooltip"/>
18+
<render args="buttonTpl" />
19+
<div class="admin__field-note" if="$data.notice">
20+
<span text="notice"/>
21+
</div>
22+
</div>
23+
</div>

0 commit comments

Comments
 (0)