Skip to content

Commit 3e100d5

Browse files
author
Andrii Kasian
committed
Merge remote-tracking branch 'origin/MAGETWO-37363' into S67
2 parents af78891 + 71caa8b commit 3e100d5

File tree

11 files changed

+174
-59
lines changed

11 files changed

+174
-59
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Front.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
*/
1212
namespace Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab;
1313

14+
use Magento\Backend\Block\Template\Context;
1415
use Magento\Backend\Block\Widget\Form;
1516
use Magento\Backend\Block\Widget\Form\Generic;
1617
use Magento\Config\Model\Config\Source\Yesno;
1718
use Magento\Catalog\Model\Entity\Attribute;
19+
use Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker;
20+
use Magento\Framework\Data\FormFactory;
21+
use Magento\Framework\Registry;
1822

1923
class Front extends Generic
2024
{
@@ -24,28 +28,28 @@ class Front extends Generic
2428
protected $_yesNo;
2529

2630
/**
27-
* @var array
31+
* @var PropertyLocker
2832
*/
29-
private $disableSearchable;
33+
private $propertyLocker;
3034

3135
/**
32-
* @param \Magento\Backend\Block\Template\Context $context
33-
* @param \Magento\Framework\Registry $registry
34-
* @param \Magento\Framework\Data\FormFactory $formFactory
36+
* @param Context $context
37+
* @param Registry $registry
38+
* @param FormFactory $formFactory
3539
* @param Yesno $yesNo
40+
* @param PropertyLocker $propertyLocker
3641
* @param array $data
37-
* @param array $disableSearchable
3842
*/
3943
public function __construct(
40-
\Magento\Backend\Block\Template\Context $context,
41-
\Magento\Framework\Registry $registry,
42-
\Magento\Framework\Data\FormFactory $formFactory,
44+
Context $context,
45+
Registry $registry,
46+
FormFactory $formFactory,
4347
Yesno $yesNo,
44-
array $data = [],
45-
array $disableSearchable = []
48+
PropertyLocker $propertyLocker,
49+
array $data = []
4650
) {
4751
$this->_yesNo = $yesNo;
48-
$this->disableSearchable = $disableSearchable;
52+
$this->propertyLocker = $propertyLocker;
4953
parent::__construct($context, $registry, $formFactory, $data);
5054
}
5155

@@ -71,7 +75,6 @@ protected function _prepareForm()
7175
['legend' => __('Frontend Properties'), 'collapsable' => $this->getRequest()->has('popup')]
7276
);
7377

74-
$attrCode = $attributeObject->getAttributeCode();
7578
$fieldset->addField(
7679
'is_searchable',
7780
'select',
@@ -80,7 +83,6 @@ protected function _prepareForm()
8083
'label' => __('Use in Search'),
8184
'title' => __('Use in Search'),
8285
'values' => $yesnoSource,
83-
'disabled' => isset($this->disableSearchable[$attrCode]) && $this->disableSearchable[$attrCode] ? 1 : 0
8486
]
8587
);
8688

@@ -223,6 +225,7 @@ protected function _prepareForm()
223225
);
224226

225227
$form->setValues($attributeObject->getData());
228+
$this->propertyLocker->lock($form);
226229
$this->setForm($form);
227230
return parent::_prepareForm();
228231
}

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Main.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ protected function _prepareForm()
6161
$response = new \Magento\Framework\Object();
6262
$response->setTypes([]);
6363
$this->_eventManager->dispatch('adminhtml_product_attribute_types', ['response' => $response]);
64-
$_disabledTypes = [];
6564
$_hiddenFields = [];
6665
foreach ($response->getTypes() as $type) {
6766
$additionalTypes[] = $type;

app/code/Magento/Catalog/Model/Product/Attribute/Source/Inputtype.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public function toOptionArray()
5353
$response = new \Magento\Framework\Object();
5454
$response->setTypes([]);
5555
$this->_eventManager->dispatch('adminhtml_product_attribute_types', ['response' => $response]);
56-
$_disabledTypes = [];
5756
$_hiddenFields = [];
5857
foreach ($response->getTypes() as $type) {
5958
$inputTypes[] = $type;

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,4 @@
6666
<type name="Magento\Catalog\Model\Resource\Attribute">
6767
<plugin name="invalidate_pagecache_after_attribute_save" type="Magento\Catalog\Plugin\Model\Resource\Attribute\Save" />
6868
</type>
69-
<type name="Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Front">
70-
<arguments>
71-
<argument name="disableSearchable" xsi:type="array">
72-
<item name="visibility" xsi:type="boolean">true</item>
73-
<item name="url_key" xsi:type="boolean">true</item>
74-
<item name="status" xsi:type="boolean">true</item>
75-
<item name="group_price" xsi:type="boolean">true</item>
76-
<item name="price_type" xsi:type="boolean">true</item>
77-
<item name="category_ids" xsi:type="boolean">true</item>
78-
<item name="media_gallery" xsi:type="boolean">true</item>
79-
<item name="country_of_manufacture" xsi:type="boolean">true</item>
80-
</argument>
81-
</arguments>
82-
</type>
8369
</config>

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,31 @@
1212
<field code="is_unique" locked="true" />
1313
</attribute>
1414
<attribute code="status">
15+
<field code="is_searchable" locked="true" />
1516
<field code="is_filterable" locked="true" />
1617
<field code="is_filterable_in_search" locked="true" />
1718
</attribute>
1819
<attribute code="visibility">
20+
<field code="is_searchable" locked="true" />
1921
<field code="is_filterable" locked="true" />
2022
<field code="is_filterable_in_search" locked="true" />
2123
</attribute>
24+
<attribute code="country_of_manufacture">
25+
<field code="is_searchable" locked="true" />
26+
<field code="is_filterable" locked="true" />
27+
<field code="is_filterable_in_search" locked="true" />
28+
</attribute>
29+
<attribute code="group_price">
30+
<field code="is_searchable" locked="true" />
31+
</attribute>
32+
<attribute code="price_type">
33+
<field code="is_searchable" locked="true" />
34+
</attribute>
35+
<attribute code="category_ids">
36+
<field code="is_searchable" locked="true" />
37+
</attribute>
38+
<attribute code="media_gallery">
39+
<field code="is_searchable" locked="true" />
40+
</attribute>
2241
</entity>
2342
</config>

app/code/Magento/CatalogUrlRewrite/etc/eav_attributes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<entity type="catalog_product">
1010
<attribute code="url_key">
1111
<field code="is_unique" locked="true" />
12+
<field code="is_searchable" locked="true" />
1213
</attribute>
1314
</entity>
1415
</config>

app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.php

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ abstract class AbstractMain extends \Magento\Backend\Block\Widget\Form\Generic
3232
protected $_eavData = null;
3333

3434
/**
35-
* @var \Magento\Eav\Model\Entity\Attribute\Config
35+
* @var \Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker
3636
*/
37-
protected $_attributeConfig;
37+
protected $propertyLocker;
3838

3939
/**
4040
* @var \Magento\Config\Model\Config\Source\YesnoFactory
@@ -53,7 +53,7 @@ abstract class AbstractMain extends \Magento\Backend\Block\Widget\Form\Generic
5353
* @param \Magento\Eav\Helper\Data $eavData
5454
* @param \Magento\Config\Model\Config\Source\YesnoFactory $yesnoFactory
5555
* @param \Magento\Eav\Model\Adminhtml\System\Config\Source\InputtypeFactory $inputTypeFactory
56-
* @param \Magento\Eav\Model\Entity\Attribute\Config $attributeConfig
56+
* @param \Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker $propertyLocker
5757
* @param array $data
5858
*/
5959
public function __construct(
@@ -63,13 +63,13 @@ public function __construct(
6363
\Magento\Eav\Helper\Data $eavData,
6464
\Magento\Config\Model\Config\Source\YesnoFactory $yesnoFactory,
6565
\Magento\Eav\Model\Adminhtml\System\Config\Source\InputtypeFactory $inputTypeFactory,
66-
\Magento\Eav\Model\Entity\Attribute\Config $attributeConfig,
66+
\Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker $propertyLocker,
6767
array $data = []
6868
) {
6969
$this->_eavData = $eavData;
7070
$this->_yesnoFactory = $yesnoFactory;
7171
$this->_inputTypeFactory = $inputTypeFactory;
72-
$this->_attributeConfig = $attributeConfig;
72+
$this->propertyLocker = $propertyLocker;
7373
parent::__construct($context, $registry, $formFactory, $data);
7474
}
7575

@@ -257,6 +257,7 @@ protected function _prepareForm()
257257
}
258258
}
259259

260+
$this->propertyLocker->lock($form);
260261
$this->setForm($form);
261262

262263
return parent::_prepareForm();
@@ -277,27 +278,6 @@ protected function _initFormValues()
277278
return parent::_initFormValues();
278279
}
279280

280-
/**
281-
* This method is called before rendering HTML
282-
*
283-
* @return $this
284-
*/
285-
protected function _beforeToHtml()
286-
{
287-
parent::_beforeToHtml();
288-
$attributeObject = $this->getAttributeObject();
289-
if ($attributeObject->getId()) {
290-
$form = $this->getForm();
291-
foreach ($this->_attributeConfig->getLockedFields($attributeObject) as $field) {
292-
if ($element = $form->getElement($field)) {
293-
$element->setDisabled(1);
294-
$element->setReadonly(1);
295-
}
296-
}
297-
}
298-
return $this;
299-
}
300-
301281
/**
302282
* Processing block html after rendering
303283
* Adding js block to the end of this block
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Eav\Block\Adminhtml\Attribute;
7+
8+
use Magento\Framework\Registry;
9+
use Magento\Eav\Model\Entity\Attribute\Config;
10+
11+
/**
12+
* Disable form fields
13+
*
14+
* @author Magento Core Team <core@magentocommerce.com>
15+
*/
16+
class PropertyLocker
17+
{
18+
/**
19+
* @var Config
20+
*/
21+
private $attributeConfig;
22+
23+
/**
24+
* @var Registry
25+
*/
26+
protected $registry;
27+
28+
/**
29+
* @param Registry $registry
30+
* @param Config $attributeConfig
31+
*/
32+
public function __construct(
33+
Registry $registry,
34+
Config $attributeConfig
35+
) {
36+
$this->registry = $registry;
37+
$this->attributeConfig = $attributeConfig;
38+
}
39+
40+
/**
41+
* @param \Magento\Framework\Data\Form $form
42+
* @return void
43+
*/
44+
public function lock(\Magento\Framework\Data\Form $form)
45+
{
46+
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attributeObject */
47+
$attributeObject = $this->registry->registry('entity_attribute');
48+
if ($attributeObject->getId()) {
49+
foreach ($this->attributeConfig->getLockedFields($attributeObject) as $field) {
50+
if ($element = $form->getElement($field)) {
51+
$element->setDisabled(1);
52+
$element->setReadonly(1);
53+
}
54+
}
55+
}
56+
}
57+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Eav\Test\Unit\Block\Adminhtml\Attribute;
7+
8+
use Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker;
9+
10+
class PropertyLockerTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/** @var PropertyLocker */
13+
protected $object;
14+
15+
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute|\PHPUnit_Framework_MockObject_MockObject */
16+
protected $attributeMock;
17+
18+
/** @var \Magento\Framework\Data\Form|\PHPUnit_Framework_MockObject_MockObject */
19+
protected $formMock;
20+
21+
/** @var \Magento\Eav\Model\Entity\Attribute\Config|\PHPUnit_Framework_MockObject_MockObject */
22+
protected $attributeConfigMock;
23+
24+
protected function setUp()
25+
{
26+
$this->attributeMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\AbstractAttribute')
27+
->setMethods(['getId'])
28+
->disableOriginalConstructor()
29+
->getMock();
30+
31+
$registryMock = $this->getMockBuilder('\Magento\Framework\Registry')
32+
->setMethods(['registry'])
33+
->disableOriginalConstructor()
34+
->getMock();
35+
$registryMock->expects($this->atLeastOnce())->method('registry')->willReturn($this->attributeMock);
36+
37+
$this->attributeConfigMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute\Config')
38+
->setMethods(['getLockedFields'])
39+
->disableOriginalConstructor()
40+
->getMock();
41+
42+
$this->formMock = $this->getMockBuilder('Magento\Framework\Data\Form')
43+
->setMethods(['getElement'])
44+
->disableOriginalConstructor()
45+
->getMock();
46+
47+
$this->object = new PropertyLocker($registryMock, $this->attributeConfigMock);
48+
}
49+
50+
/**
51+
* @covers \Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker::lock
52+
*/
53+
public function testLock()
54+
{
55+
$lockedFields = [
56+
'is_searchable' => 'is_searchable',
57+
'is_filterable' => 'is_filterable'
58+
];
59+
$this->attributeMock->expects($this->once())->method('getId')->willReturn(1);
60+
$this->attributeConfigMock->expects($this->once())->method('getLockedFields')->willReturn($lockedFields);
61+
62+
$elementMock = $this->getMockBuilder('\Magento\Framework\Data\Form\Element\AbstractElement')
63+
->setMethods(['setDisabled', 'setReadonly'])
64+
->disableOriginalConstructor()
65+
->getMockForAbstractClass();
66+
$elementMock->expects($this->exactly(2))->method('setDisabled');
67+
$elementMock->expects($this->exactly(2))->method('setReadonly');
68+
$this->formMock->expects($this->exactly(2))->method('getElement')->willReturn($elementMock);
69+
$this->object->lock($this->formMock);
70+
}
71+
}

dev/tests/integration/testsuite/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/FrontTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testToHtml($attributeCode)
3737
{
3838
/** @var \Magento\Catalog\Model\Resource\Eav\Attribute $model */
3939
$model = $this->objectManager->create('Magento\Catalog\Model\Resource\Eav\Attribute');
40-
$model->load($attributeCode, 'attribute_code');
40+
$model->loadByCode(\Magento\Catalog\Model\Product::ENTITY, $attributeCode);
4141

4242
/** @var \Magento\Framework\Registry $coreRegistry */
4343
$coreRegistry = $this->objectManager->get('\Magento\Framework\Registry');

0 commit comments

Comments
 (0)