-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.4-develop' into fix-24357
- Loading branch information
Showing
181 changed files
with
8,165 additions
and
2,468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,60 +7,60 @@ | |
/** | ||
* Product attribute add/edit form main tab | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
namespace Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab; | ||
|
||
use Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Apply as HelperApply; | ||
use Magento\Eav\Block\Adminhtml\Attribute\Edit\Main\AbstractMain; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Magento\Framework\Data\Form\Element\Fieldset; | ||
use Magento\Framework\DataObject; | ||
|
||
/** | ||
* Product attribute add/edit form main tab | ||
* | ||
* @api | ||
* @SuppressWarnings(PHPMD.DepthOfInheritance) | ||
* @since 100.0.2 | ||
*/ | ||
class Main extends AbstractMain | ||
{ | ||
/** | ||
* Adding product form elements for editing attribute | ||
* | ||
* @return $this | ||
* @SuppressWarnings(PHPMD.UnusedLocalVariable) | ||
* @inheritdoc | ||
*/ | ||
protected function _prepareForm() | ||
{ | ||
parent::_prepareForm(); | ||
/** @var \Magento\Catalog\Model\ResourceModel\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'); | ||
$fieldsToRemove = ['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); | ||
} | ||
$this->removeUnusedFields(); | ||
$this->processFrontendInputTypes(); | ||
|
||
$this->_eventManager->dispatch('product_attribute_form_build_main_tab', ['form' => $this->getForm()]); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _getAdditionalElementTypes() | ||
{ | ||
return ['apply' => HelperApply::class]; | ||
} | ||
|
||
/** | ||
* Process frontend input types for product attributes | ||
* | ||
* @return void | ||
*/ | ||
private function processFrontendInputTypes(): void | ||
{ | ||
$form = $this->getForm(); | ||
/** @var AbstractElement $frontendInputElm */ | ||
$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()], | ||
]; | ||
} | ||
$additionalTypes = $this->getAdditionalFrontendInputTypes(); | ||
|
||
$response = new \Magento\Framework\DataObject(); | ||
$response = new DataObject(); | ||
$response->setTypes([]); | ||
$this->_eventManager->dispatch('adminhtml_product_attribute_types', ['response' => $response]); | ||
$_hiddenFields = []; | ||
|
@@ -74,19 +74,51 @@ protected function _prepareForm() | |
|
||
$frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes); | ||
$frontendInputElm->setValues($frontendInputValues); | ||
} | ||
|
||
$this->_eventManager->dispatch('product_attribute_form_build_main_tab', ['form' => $form]); | ||
/** | ||
* Get additional Frontend Input Types for product attributes | ||
* | ||
* @return array | ||
*/ | ||
private function getAdditionalFrontendInputTypes(): array | ||
{ | ||
$additionalTypes = [ | ||
['value' => 'price', 'label' => __('Price')], | ||
['value' => 'media_image', 'label' => __('Media Image')], | ||
]; | ||
|
||
return $this; | ||
$additionalReadOnlyTypes = ['gallery' => __('Gallery')]; | ||
$attributeObject = $this->getAttributeObject(); | ||
if (isset($additionalReadOnlyTypes[$attributeObject->getFrontendInput()])) { | ||
$additionalTypes[] = [ | ||
'value' => $attributeObject->getFrontendInput(), | ||
'label' => $additionalReadOnlyTypes[$attributeObject->getFrontendInput()], | ||
]; | ||
} | ||
|
||
return $additionalTypes; | ||
} | ||
|
||
/** | ||
* Retrieve additional element types for product attributes | ||
* Remove unused form fields | ||
* | ||
* @return array | ||
* @return void | ||
*/ | ||
protected function _getAdditionalElementTypes() | ||
private function removeUnusedFields(): void | ||
{ | ||
return ['apply' => \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Apply::class]; | ||
$form = $this->getForm(); | ||
/* @var $fieldset Fieldset */ | ||
$fieldset = $form->getElement('base_fieldset'); | ||
$fieldsToRemove = ['attribute_code', 'is_unique', 'frontend_class']; | ||
foreach ($fieldset->getElements() as $element) { | ||
/** @var AbstractElement $element */ | ||
if (substr($element->getId(), 0, strlen('default_value')) === 'default_value') { | ||
$fieldsToRemove[] = $element->getId(); | ||
} | ||
} | ||
foreach ($fieldsToRemove as $id) { | ||
$fieldset->removeField($id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.