Beispiel #1
0
 /**
  * Adding product form elements for editing attribute
  *
  * @return \Magento\ConfigurableProduct\Block\Adminhtml\Product\Attribute\Edit\Tab\Variations\Main
  */
 protected function _prepareForm()
 {
     parent::_prepareForm();
     /* @var $form \Magento\Framework\Data\Form */
     $form = $this->getForm();
     /* @var $fieldset \Magento\Framework\Data\Form\Element\Fieldset */
     $fieldset = $form->getElement('base_fieldset');
     $fieldsToRemove = array('attribute_code', 'is_unique', 'frontend_class');
     foreach ($fieldset->getElements() as $element) {
         /** @var \Magento\Framework\Data\Form\AbstractForm $element  */
         if (substr($element->getId(), 0, strlen('default_value')) == 'default_value') {
             $fieldsToRemove[] = $element->getId();
         }
     }
     foreach ($fieldsToRemove as $id) {
         $fieldset->removeField($id);
     }
     return $this;
 }
Beispiel #2
0
 /**
  * Adding product form elements for editing attribute
  *
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 protected function _prepareForm()
 {
     parent::_prepareForm();
     /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attributeObject */
     $attributeObject = $this->getAttributeObject();
     /* @var $form \Magento\Framework\Data\Form */
     $form = $this->getForm();
     /* @var $fieldset \Magento\Framework\Data\Form\Element\Fieldset */
     $fieldset = $form->getElement('base_fieldset');
     $fiedsToRemove = ['attribute_code', 'is_unique', 'frontend_class'];
     foreach ($fieldset->getElements() as $element) {
         /** @var \Magento\Framework\Data\Form\AbstractForm $element  */
         if (substr($element->getId(), 0, strlen('default_value')) == 'default_value') {
             $fiedsToRemove[] = $element->getId();
         }
     }
     foreach ($fiedsToRemove as $id) {
         $fieldset->removeField($id);
     }
     $frontendInputElm = $form->getElement('frontend_input');
     $additionalTypes = [['value' => 'price', 'label' => __('Price')], ['value' => 'media_image', 'label' => __('Media Image')]];
     $additionalReadOnlyTypes = ['gallery' => __('Gallery')];
     if (isset($additionalReadOnlyTypes[$attributeObject->getFrontendInput()])) {
         $additionalTypes[] = ['value' => $attributeObject->getFrontendInput(), 'label' => $additionalReadOnlyTypes[$attributeObject->getFrontendInput()]];
     }
     $response = new \Magento\Framework\Object();
     $response->setTypes([]);
     $this->_eventManager->dispatch('adminhtml_product_attribute_types', ['response' => $response]);
     $_disabledTypes = [];
     $_hiddenFields = [];
     foreach ($response->getTypes() as $type) {
         $additionalTypes[] = $type;
         if (isset($type['hide_fields'])) {
             $_hiddenFields[$type['value']] = $type['hide_fields'];
         }
     }
     $this->_coreRegistry->register('attribute_type_hidden_fields', $_hiddenFields);
     $frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes);
     $frontendInputElm->setValues($frontendInputValues);
     return $this;
 }