Skip to content

Commit

Permalink
Varien_Data_Form_Element_Renderer_Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Jan 10, 2025
1 parent c6d3bd8 commit 13cf4f6
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ protected function _prepareForm()
) {
$fieldset->removeField('url_key');
} else {
$form->getElement('url_key')->setRenderer(
$this->getLayout()->createBlock('adminhtml/catalog_form_renderer_attribute_urlkey'),
);
$renderer = $this->getLayout()->createBlock('adminhtml/catalog_form_renderer_attribute_urlkey');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$form->getElement('url_key')->setRenderer($renderer);
}
}
}
}
Expand Down
24 changes: 15 additions & 9 deletions app/code/core/Mage/Adminhtml/Block/Catalog/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ class Mage_Adminhtml_Block_Catalog_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareLayout()
{
Varien_Data_Form::setElementRenderer(
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_element'),
);
Varien_Data_Form::setFieldsetRenderer(
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset'),
);
Varien_Data_Form::setFieldsetElementRenderer(
$this->getLayout()->createBlock('adminhtml/catalog_form_renderer_fieldset_element'),
);
$renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_element');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
Varien_Data_Form::setElementRenderer($renderer);
}

$renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
Varien_Data_Form::setFieldsetRenderer($renderer);
}

$renderer = $this->getLayout()->createBlock('adminhtml/catalog_form_renderer_fieldset_element');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
Varien_Data_Form::setFieldsetElementRenderer($renderer);
}

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,21 @@ protected function _prepareForm()

$this->_setFieldset($attributes, $fieldset, ['gallery']);

$urlKey = $form->getElement('url_key');
if ($urlKey) {
$urlKey->setRenderer(
$this->getLayout()->createBlock('adminhtml/catalog_form_renderer_attribute_urlkey'),
);
}

$tierPrice = $form->getElement('tier_price');
if ($tierPrice) {
$tierPrice->setRenderer(
$this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_price_tier'),
);
}

$groupPrice = $form->getElement('group_price');
if ($groupPrice) {
$groupPrice->setRenderer(
$this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_price_group'),
);
}

$recurringProfile = $form->getElement('recurring_profile');
if ($recurringProfile) {
$recurringProfile->setRenderer(
$this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_price_recurring'),
);
$rendererBlocks = [
'url_key' => 'adminhtml/catalog_form_renderer_attribute_urlkey',
'tier_price' => 'adminhtml/catalog_product_edit_tab_price_tier',
'group_price' => 'adminhtml/catalog_product_edit_tab_price_group',
'recurring_profile' => 'adminhtml/catalog_product_edit_tab_price_recurring',
];

foreach ($rendererBlocks as $elementId => $rendererBlock) {
$element = $form->getElement($elementId);
if ($element) {
$renderer = $this->getLayout()->createBlock($rendererBlock);
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$element->setRenderer($renderer);
}
}
}

// Add new attribute button if it is not an image tab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ protected function _prepareForm()
'value' => $product->getData('tier_price'),
]);

$form->getElement('tier_price')->setRenderer(
$this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_price_tier'),
);
$renderer = $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_price_tier');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$form->getElement('tier_price')->setRenderer($renderer);
}

$this->setForm($form);
return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ protected function _prepareForm()
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(true, false),
'required' => true,
]);

$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset_element');
$field->setRenderer($renderer);
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$fieldset->setRenderer($renderer);
}
} else {
$fieldset->addField('store_id', 'hidden', [
'name' => 'store_id',
Expand Down
18 changes: 15 additions & 3 deletions app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ function(v, elem){
->__('Password must be at least of %d characters.', $minPasswordLength),
],
);
$field->setRenderer($this->getLayout()->createBlock('adminhtml/customer_edit_renderer_newpass'));

$renderer = $this->getLayout()->createBlock('adminhtml/customer_edit_renderer_newpass');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$fieldset->setRenderer($renderer);
}

// Prepare customer confirmation control (only for existing customers)
$confirmationKey = $customer->getConfirmation();
Expand Down Expand Up @@ -202,7 +206,11 @@ function(v, elem){
'required' => true,
],
);
$field->setRenderer($this->getLayout()->createBlock('adminhtml/customer_edit_renderer_adminpass'));

$renderer = $this->getLayout()->createBlock('adminhtml/customer_edit_renderer_adminpass');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$fieldset->setRenderer($renderer);
}
}
}
} else {
Expand All @@ -222,7 +230,11 @@ function(v, elem){
->__('Password must be at least of %d characters.', $minPasswordLength),
],
);
$field->setRenderer($this->getLayout()->createBlock('adminhtml/customer_edit_renderer_newpass'));

$renderer = $this->getLayout()->createBlock('adminhtml/customer_edit_renderer_newpass');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$fieldset->setRenderer($renderer);
}

// Prepare send welcome email checkbox
$fieldset->addField('sendemail', 'checkbox', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ protected function _prepareForm()
'legend' => Mage::helper('salesrule')->__('Store View Specific Labels'),
'table_class' => 'form-list stores-tree',
]);

$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset');
$fieldset->setRenderer($renderer);
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$fieldset->setRenderer($renderer);
}

foreach (Mage::app()->getWebsites() as $website) {
$fieldset->addField("w_{$website->getId()}_label", 'note', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ protected function _prepareForm()
'checked' => (int) $model->getUseAutoGeneration() > 0 ? 'checked' : '',
]);

$autoGenerationCheckbox->setRenderer(
$this->getLayout()->createBlock('adminhtml/promo_quote_edit_tab_main_renderer_checkbox'),
);
$renderer = $this->getLayout()->createBlock('adminhtml/promo_quote_edit_tab_main_renderer_checkbox');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$autoGenerationCheckbox->setRenderer($renderer);
}

$usesPerCouponFiled = $fieldset->addField('uses_per_coupon', 'text', [
'name' => 'uses_per_coupon',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@ protected function _prepareLayout()
{
parent::_prepareLayout();

Varien_Data_Form::setElementRenderer(
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_element'),
);
Varien_Data_Form::setFieldsetRenderer(
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset'),
);
Varien_Data_Form::setFieldsetElementRenderer(
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element'),
);
$renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_element');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
Varien_Data_Form::setElementRenderer($renderer);
}

$renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
Varien_Data_Form::setFieldsetRenderer($renderer);
}

$renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
Varien_Data_Form::setFieldsetElementRenderer($renderer);
}

return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ protected function _prepareForm()
'legend' => Mage::helper('sales')->__('Store View Specific Labels'),
'table_class' => 'form-list stores-tree',
]);

$renderer = $this->getLayout()->createBlock('adminhtml/store_switcher_form_renderer_fieldset');
$fieldset->setRenderer($renderer);
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$fieldset->setRenderer($renderer);
}

foreach (Mage::app()->getWebsites() as $website) {
$fieldset->addField("w_{$website->getId()}_label", 'note', [
Expand Down
23 changes: 14 additions & 9 deletions app/code/core/Mage/Adminhtml/Block/Widget/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,20 @@ protected function _construct()
*/
protected function _prepareLayout()
{
Varien_Data_Form::setElementRenderer(
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_element'),
);
Varien_Data_Form::setFieldsetRenderer(
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset'),
);
Varien_Data_Form::setFieldsetElementRenderer(
$this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element'),
);
$renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_element');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
Varien_Data_Form::setElementRenderer($renderer);
}

$renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
Varien_Data_Form::setFieldsetRenderer($renderer);
}

$renderer = $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
Varien_Data_Form::setFieldsetElementRenderer($renderer);
}

return parent::_prepareLayout();
}
Expand Down
21 changes: 18 additions & 3 deletions app/code/core/Mage/Rule/Model/Action/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,37 +254,52 @@ public function getTypeElement()
*/
public function getAttributeElement()
{
$renderer = Mage::getBlockSingleton('rule/editable');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$this->getForm()::setFieldsetRenderer($renderer);
}

return $this->getForm()->addField('action:' . $this->getId() . ':attribute', 'select', [
'name' => 'rule[actions][' . $this->getId() . '][attribute]',
'values' => $this->getAttributeSelectOptions(),
'value' => $this->getAttribute(),
'value_name' => $this->getAttributeName(),
])->setRenderer(Mage::getBlockSingleton('rule/editable'));
]);
}

/**
* @return Varien_Data_Form_Element_Abstract
*/
public function getOperatorElement()
{
$renderer = Mage::getBlockSingleton('rule/editable');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$this->getForm()::setFieldsetRenderer($renderer);
}

return $this->getForm()->addField('action:' . $this->getId() . ':operator', 'select', [
'name' => 'rule[actions][' . $this->getId() . '][operator]',
'values' => $this->getOperatorSelectOptions(),
'value' => $this->getOperator(),
'value_name' => $this->getOperatorName(),
])->setRenderer(Mage::getBlockSingleton('rule/editable'));
]);
}

/**
* @return Varien_Data_Form_Element_Abstract
*/
public function getValueElement()
{
$renderer = Mage::getBlockSingleton('rule/editable');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$this->getForm()::setFieldsetRenderer($renderer);
}

return $this->getForm()->addField('action:' . $this->getId() . ':value', 'text', [
'name' => 'rule[actions][' . $this->getId() . '][value]',
'value' => $this->getValue(),
'value_name' => $this->getValueName(),
])->setRenderer(Mage::getBlockSingleton('rule/editable'));
]);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion app/code/core/Mage/Rule/Model/Action/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,16 @@ public function asHtml()
*/
public function getNewChildElement()
{
$renderer = Mage::getBlockSingleton('rule/newchild');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$this->getForm()::setFieldsetRenderer($renderer);
}

return $this->getForm()->addField('action:' . $this->getId() . ':new_child', 'select', [
'name' => 'rule[actions][' . $this->getId() . '][new_child]',
'values' => $this->getNewChildSelectOptions(),
'value_name' => $this->getNewChildName(),
])->setRenderer(Mage::getBlockSingleton('rule/newchild'));
]);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions app/code/core/Mage/Rule/Model/Condition/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,18 @@ public function getAttributeElement()
break;
}
}

$renderer = Mage::getBlockSingleton('rule/editable');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$this->getForm()::setFieldsetRenderer($renderer);
}

return $this->getForm()->addField($this->getPrefix() . '__' . $this->getId() . '__attribute', 'select', [
'name' => 'rule[' . $this->getPrefix() . '][' . $this->getId() . '][attribute]',
'values' => $this->getAttributeSelectOptions(),
'value' => $this->getAttribute(),
'value_name' => $this->getAttributeName(),
])->setRenderer(Mage::getBlockSingleton('rule/editable'));
]);
}

/**
Expand Down Expand Up @@ -548,7 +554,11 @@ public function getOperatorElement()
'value' => $this->getOperator(),
'value_name' => $this->getOperatorName(),
]);
$element->setRenderer(Mage::getBlockSingleton('rule/editable'));

$renderer = Mage::getBlockSingleton('rule/editable');
if ($renderer instanceof Varien_Data_Form_Element_Renderer_Interface) {
$element->setRenderer($renderer);
}

return $element;
}
Expand Down
Loading

0 comments on commit 13cf4f6

Please sign in to comment.