Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI to Edit EAV Attributes & Sets - Base Code + Category #2317

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
54a9265
Mage_Eav: add generic grid code
justinbeaty Jul 13, 2022
23358e5
Mage_Catalog: add EAV grids
justinbeaty Jul 13, 2022
7da0878
Merge branch '20.0' into topic-eav-grid-category
sreichel Aug 8, 2022
ce499a9
Mage_Eav: Add generic grid code
justinbeaty Aug 3, 2022
d34bde9
Mage_Eav: Add generic form element renderers
justinbeaty Aug 3, 2022
fe41496
Merge branch main
fballiano Jul 29, 2023
80d7f81
phpcs
fballiano Jul 29, 2023
fde88f4
Merge branch main
fballiano Jul 29, 2023
2c48574
phpcs
fballiano Jul 29, 2023
15034ca
Merge branch 'main' into topic-eav-grid
fballiano Jan 26, 2024
0293762
PHPStan
fballiano Jan 26, 2024
9dd0a4e
slightly better whitespace
fballiano Jan 26, 2024
5109615
short array format + whitespace
fballiano Jan 26, 2024
97b06aa
Merge branch 'main' into topic-eav-grid
fballiano Apr 22, 2024
b666ce6
phpcs
fballiano Apr 22, 2024
c6f1ff5
array
fballiano Apr 22, 2024
b0be74d
array
fballiano Apr 22, 2024
cdb6f8a
array
fballiano Apr 22, 2024
1bbec40
array
fballiano Apr 22, 2024
0440e6c
array
fballiano Apr 22, 2024
cb87b61
phpcs
fballiano Apr 22, 2024
558ee5d
phpcs
fballiano Apr 22, 2024
7de5ccd
phpstan
fballiano Apr 22, 2024
da9559a
type hint
fballiano Apr 22, 2024
19f41d5
Merge branch 'main' into topic-eav-grid
sreichel Sep 17, 2024
69815b5
Merge branch 'main' into topic-eav-grid-category
sreichel Sep 17, 2024
9596137
Merge branch 'main' into topic-eav-grid-category
sreichel Sep 19, 2024
b6c76b8
phpcs + syntax-error
sreichel Sep 19, 2024
c19efe5
Merge branch 'main' into topic-eav-grid
sreichel Sep 19, 2024
ddf34c0
phpcs
sreichel Sep 19, 2024
cd41653
Merge branch 'main' into topic-eav-grid-category
sreichel Sep 19, 2024
d3e5c31
Merge branch 'main' into topic-eav-grid
sreichel Sep 19, 2024
4cf4d00
phpcbf
sreichel Sep 19, 2024
7dd9002
Cleanup [skip ci]
sreichel Sep 19, 2024
0f8e1ec
Trigger CI
sreichel Sep 19, 2024
64fc93f
Rollback wrong copyright changes
sreichel Sep 21, 2024
b84abdb
Rollback wrong copyright changes
sreichel Sep 21, 2024
014b548
Merge branch 'main' into topic-eav-grid
sreichel Sep 23, 2024
daada40
Merge branch 'main' into topic-eav-grid-category
sreichel Sep 23, 2024
d486ead
Rector fixes
sreichel Sep 23, 2024
87cc66c
Merge branch 'main' into topic-eav-grid
sreichel Sep 23, 2024
6e2efe2
Merge branch 'main' into topic-eav-grid-category
sreichel Sep 24, 2024
a3c1511
Added return types
sreichel Sep 24, 2024
ff97f9d
added strict types
sreichel Sep 24, 2024
49f6e8d
Merge branch 'topic-eav-grid-category' into topic-eav-grid
sreichel Sep 24, 2024
1687b1e
Fixed controllers
sreichel Sep 24, 2024
de2b198
Fixed active menu
sreichel Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
| admin_user_authenticate_after | 1.9.4.5 |
| admin_user_authenticate_before | 1.9.4.5 |
| admin_user_validate | 1.9.4.5 |
| adminhtml_[entityCode]_attribute_types | 22.0.0 |
| adminhtml_[entityCode]_attribute_scopes | 22.0.0 |
| adminhtml_[entityCode]_attribute_edit_prepare_form | 22.0.0 |
fballiano marked this conversation as resolved.
Show resolved Hide resolved
| adminhtml_block_eav_attribute_edit_form_init | 1.9.4.5 |
| adminhtml_block_promo_widget_chooser_prepare_collection | 1.9.4.5 |
| adminhtml_block_salesrule_actions_prepareform | 1.9.4.5 |
Expand Down
4 changes: 0 additions & 4 deletions app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@
*/
class Mage_Catalog_Model_Resource_Eav_Attribute extends Mage_Eav_Model_Entity_Attribute
{
const SCOPE_STORE = 0;
const SCOPE_GLOBAL = 1;
const SCOPE_WEBSITE = 2;

const MODULE_NAME = 'Mage_Catalog';
const ENTITY = 'catalog_eav_attribute';

Expand Down
49 changes: 49 additions & 0 deletions app/code/core/Mage/Eav/Block/Adminhtml/Attribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* OpenMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Eav
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Adminhtml attributes block
*
* @category Mage
* @package Mage_Eav
* @author Magento Core Team <core@magentocommerce.com>
*/

class Mage_Eav_Block_Adminhtml_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_blockGroup = 'eav';
$this->_controller = 'adminhtml_attribute';
if ($entity_type = Mage::registry('entity_type')) {
$this->_headerText = Mage::helper('eav')->__('Manage %s Attributes', Mage::helper('eav')->formatTypeCode($entity_type));
} else {
$this->_headerText = Mage::helper('eav')->__('Manage Attributes');
}
$this->_addButtonLabel = Mage::helper('eav')->__('Add New Attribute');
parent::__construct();
}

public function getHeaderCssClass()
{
return 'icon-head head-eav-attribute';
}

}
81 changes: 81 additions & 0 deletions app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* OpenMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Eav
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Mage_Eav_Block_Adminhtml_Attribute_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{

public function __construct()
{
$this->_objectId = 'attribute_id';
$this->_blockGroup = 'eav';
$this->_controller = 'adminhtml_attribute';

parent::__construct();

$this->_addButton(
'save_and_edit_button',
array(
'label' => Mage::helper('eav')->__('Save and Continue Edit'),
'onclick' => 'saveAndContinueEdit()',
'class' => 'save'
),
100
);

$this->_updateButton('save', 'label', Mage::helper('eav')->__('Save Attribute'));
$this->_updateButton('save', 'onclick', 'saveAttribute()');

if (!Mage::registry('entity_attribute')->getIsUserDefined()) {
$this->_removeButton('delete');
} else {
$this->_updateButton('delete', 'label', Mage::helper('eav')->__('Delete Attribute'));
}
}

public function getHeaderText()
{
if (Mage::registry('entity_attribute')->getId()) {
$frontendLabel = Mage::registry('entity_attribute')->getFrontendLabel();
if (is_array($frontendLabel)) {
$frontendLabel = $frontendLabel[0];
}
return Mage::helper('eav')->__('Edit %s Attribute "%s"', Mage::helper('eav')->formatTypeCode(Mage::registry('entity_type')), $this->escapeHtml($frontendLabel));
}
else {
return Mage::helper('eav')->__('New %s Attribute', Mage::helper('eav')->formatTypeCode(Mage::registry('entity_type')));
}
}

public function getValidationUrl()
{
return $this->getUrl('*/*/validate', array('_current'=>true));
}

public function getSaveUrl()
{
return $this->getUrl('*/*/save', array('_current'=>true, 'back'=>null));
}

public function getHeaderCssClass()
{
return 'icon-head head-eav-attribute';
}

}
30 changes: 30 additions & 0 deletions app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* OpenMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Eav
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Mage_Eav_Block_Adminhtml_Attribute_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract extends Mag
protected $_attribute = null;

/**
* @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
* @param Mage_Eav_Model_Entity_Attribute $attribute
* @return $this
*/
public function setAttributeObject($attribute)
Expand All @@ -47,7 +47,7 @@ public function setAttributeObject($attribute)
}

/**
* @return Mage_Catalog_Model_Resource_Eav_Attribute
* @return Mage_Eav_Model_Entity_Attribute
*/
public function getAttributeObject()
{
Expand Down Expand Up @@ -103,8 +103,8 @@ protected function _prepareForm()

$fieldset->addField('frontend_input', 'select', array(
'name' => 'frontend_input',
'label' => Mage::helper('eav')->__('Catalog Input Type for Store Owner'),
'title' => Mage::helper('eav')->__('Catalog Input Type for Store Owner'),
'label' => Mage::helper('eav')->__('Input Type for Store Owner'),
'title' => Mage::helper('eav')->__('Input Type for Store Owner'),
'value' => 'text',
'values'=> $inputTypes
));
Expand Down
102 changes: 102 additions & 0 deletions app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tab/Main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* OpenMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Eav
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Mage_Eav_Block_Adminhtml_Attribute_Edit_Tab_Main extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Main_Abstract
{
/**
* Adding product form elements for editing attribute
justinbeaty marked this conversation as resolved.
Show resolved Hide resolved
*
* @return $this
*/
protected function _prepareForm()
{
parent::_prepareForm();
$attributeObject = $this->getAttributeObject();
$attributeTypeCode = $attributeObject->getEntityType()->getEntityTypeCode();
/* @var $form Varien_Data_Form */
$form = $this->getForm();
/* @var $fieldset Varien_Data_Form_Element_Fieldset */
$fieldset = $form->getElement('base_fieldset');

$fieldset->getElements()
->searchById('attribute_code')
->setData(
'class',
'validate-code-event ' . $fieldset->getElements()->searchById('attribute_code')->getData('class')
)->setData(
'note',
$fieldset->getElements()->searchById('attribute_code')->getData('note')
. Mage::helper('eav')->__('. Do not use "event" for an attribute code, it is a reserved keyword.')
);

$frontendInputElm = $form->getElement('frontend_input');
$additionalTypes = array();

$response = new Varien_Object();
$response->setTypes(array());
Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_types", array('response'=>$response));
$_disabledTypes = array();
$_hiddenFields = array();
foreach ($response->getTypes() as $type) {
$additionalTypes[] = $type;
if (isset($type['hide_fields'])) {
$_hiddenFields[$type['value']] = $type['hide_fields'];
}
if (isset($type['disabled_types'])) {
$_disabledTypes[$type['value']] = $type['disabled_types'];
}
}
Mage::register('attribute_type_hidden_fields', $_hiddenFields);
Mage::register('attribute_type_disabled_types', $_disabledTypes);

$frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes);
$frontendInputElm->setValues($frontendInputValues);

$scopes = array(
Mage_Eav_Model_Entity_Attribute::SCOPE_STORE =>Mage::helper('eav')->__('Store View'),
Mage_Eav_Model_Entity_Attribute::SCOPE_WEBSITE =>Mage::helper('eav')->__('Website'),
Mage_Eav_Model_Entity_Attribute::SCOPE_GLOBAL =>Mage::helper('eav')->__('Global'),
);

if ($attributeObject->getAttributeCode() == 'status') {
unset($scopes[Mage_Eav_Model_Entity_Attribute::SCOPE_STORE]);
}

$response = new Varien_Object();
$response->setScopes($scopes);
$response->setAttribute($attributeObject);
Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_scopes", array('response'=>$response));

$fieldset->addField('is_global', 'select', array(
'name' => 'is_global',
'label' => Mage::helper('eav')->__('Scope'),
'title' => Mage::helper('eav')->__('Scope'),
'note' => Mage::helper('eav')->__('Declare attribute value saving scope'),
'values'=> $response->getScopes(),
), 'attribute_code');

Mage::dispatchEvent("adminhtml_{$attributeTypeCode}_attribute_edit_prepare_form", array(
'form' => $form,
'attribute' => $attributeObject
));

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* OpenMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Eav
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Mage_Eav_Block_Adminhtml_Attribute_Edit_Tab_Options extends Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract
{
}
51 changes: 51 additions & 0 deletions app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Tabs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* OpenMage
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magento.com so we can send you a copy immediately.
*
* @category Mage
* @package Mage_Eav
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class Mage_Eav_Block_Adminhtml_Attribute_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
public function __construct()
{
parent::__construct();
$this->setId('eav_attribute_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(Mage::helper('eav')->__('Attribute Information'));
}

protected function _beforeToHtml()
{
$this->addTab('main', array(
'label' => Mage::helper('eav')->__('Properties'),
'title' => Mage::helper('eav')->__('Properties'),
'content' => $this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tab_main')->toHtml(),
'active' => true
));

$model = Mage::registry('entity_attribute');

$this->addTab('labels', array(
'label' => Mage::helper('eav')->__('Manage Label / Options'),
'title' => Mage::helper('eav')->__('Manage Label / Options'),
'content' => $this->getLayout()->createBlock('eav/adminhtml_attribute_edit_tab_options')->toHtml(),
));

return parent::_beforeToHtml();
}

}
Loading