public function testGetEntityAttributesLockedFields()
 {
     $data = ['entity_code' => ['attributes' => ['attribute_code' => ['attribute_data' => ['locked' => 'locked_field', 'code' => 'code_test']]]]];
     $this->_model->merge($data);
     $result = $this->_model->getEntityAttributesLockedFields('entity_code');
     $this->assertEquals(['attribute_code' => ['code_test']], $result);
 }
 /**
  * @covers \Magento\Eav\Block\Adminhtml\Attribute\PropertyLocker::lock
  */
 public function testLock()
 {
     $lockedFields = ['is_searchable' => 'is_searchable', 'is_filterable' => 'is_filterable'];
     $this->attributeMock->expects($this->once())->method('getId')->willReturn(1);
     $this->attributeConfigMock->expects($this->once())->method('getLockedFields')->willReturn($lockedFields);
     $elementMock = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement')->setMethods(['setDisabled', 'setReadonly'])->disableOriginalConstructor()->getMockForAbstractClass();
     $elementMock->expects($this->exactly(2))->method('setDisabled');
     $elementMock->expects($this->exactly(2))->method('setReadonly');
     $this->formMock->expects($this->exactly(2))->method('getElement')->willReturn($elementMock);
     $this->object->lock($this->formMock);
 }
 /**
  * @param \Magento\Framework\Data\Form $form
  * @return void
  */
 public function lock(\Magento\Framework\Data\Form $form)
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attributeObject */
     $attributeObject = $this->registry->registry('entity_attribute');
     if ($attributeObject->getId()) {
         foreach ($this->attributeConfig->getLockedFields($attributeObject) as $field) {
             if ($element = $form->getElement($field)) {
                 $element->setDisabled(1);
                 $element->setReadonly(1);
             }
         }
     }
 }
Example #4
0
 /**
  * Retrieve attributes locked fields to edit
  *
  * @param string $entityTypeCode
  * @return array
  */
 public function getAttributeLockedFields($entityTypeCode)
 {
     if (!$entityTypeCode) {
         return [];
     }
     if (isset($this->_attributesLockedFields[$entityTypeCode])) {
         return $this->_attributesLockedFields[$entityTypeCode];
     }
     $attributesLockedFields = $this->_attributeConfig->getEntityAttributesLockedFields($entityTypeCode);
     if (count($attributesLockedFields)) {
         $this->_attributesLockedFields[$entityTypeCode] = $attributesLockedFields;
         return $this->_attributesLockedFields[$entityTypeCode];
     }
     return [];
 }
Example #5
0
 /**
  * This method is called before rendering HTML
  *
  * @return $this
  */
 protected function _beforeToHtml()
 {
     parent::_beforeToHtml();
     $attributeObject = $this->getAttributeObject();
     if ($attributeObject->getId()) {
         $form = $this->getForm();
         foreach ($this->_attributeConfig->getLockedFields($attributeObject) as $field) {
             if ($element = $form->getElement($field)) {
                 $element->setDisabled(1);
                 $element->setReadonly(1);
             }
         }
     }
     return $this;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function getAttributes($extended = false)
 {
     if (!$this->attributes) {
         $collection = $this->attributeCollectionFactory->create()->addVisibleFilter()->setOrder('attribute_id', 'asc');
         /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
         foreach ($collection as $attribute) {
             $allLockedFields = $this->eavConfig->get($attribute->getEntityType()->getEntityTypeCode() . '/attributes/' . $attribute->getAttributeCode());
             if (!is_array($allLockedFields)) {
                 $allLockedFields = [];
             }
             if ($attribute->getDefaultFrontendLabel() && !isset($allLockedFields['is_searchable'])) {
                 $this->attributes[$attribute->getAttributeCode()] = $attribute->getDefaultFrontendLabel();
             }
         }
     }
     $result = $this->attributes;
     if ($extended) {
         $result['visibility'] = '';
         $result['options'] = '';
         $result['category_ids'] = '';
         $result['status'] = '';
     }
     return $result;
 }