将自定义表单元素添加到 Adminhtml 表单 [英] Adding a Custom Form Element to an Adminhtml Form

查看:38
本文介绍了将自定义表单元素添加到 Adminhtml 表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将自定义表单元素添加到 Magento Adminhtml 表单中,而无需将自定义元素放在 lib/Varian 文件夹中?

Is there a way to add a custom form element to a Magento Adminhtml form without placing the custom element in the lib/Varian folder?

我已经找到了本质上是 Varian_Data_Form_Element_ 工厂的代码

I've tracked down the code that's essentially a Varian_Data_Form_Element_ factory

public function addField($elementId, $type, $config, $after=false)
{
    if (isset($this->_types[$type])) {
        $className = $this->_types[$type];
    }
    else {
        $className = 'Varien_Data_Form_Element_'.ucfirst(strtolower($type));
    }
    $element = new $className($config);
    $element->setId($elementId);
    if ($element->getRequired()) {
        $element->addClass('required-entry');
    }
    $this->addElement($element, $after);
    return $element;
}

因此,如果我正确阅读本文,我会确保 EAV 属性的前端返回特定的 fieldType(例如 supertextfield),并且系统将实例化/呈现 Varien_Data_Form_Element_Supertextfield 显示此属性的编辑表单时.

So, if I'm reading this correctly, I ensure that an EAV attribute's frontend returns a specific fieldType, (such as supertextfield) and the system will instantiate/render a Varien_Data_Form_Element_Supertextfield when displaying this attribute's editing form.

这很好,但这意味着我需要在 lib/Varian 文件夹层次结构中包含我的自定义表单元素.鉴于 Magento 是如何面向模块的,这似乎是错误的.

This is well and good, but it means I need to include my custom form element in the lib/Varian folder hierarchy. Given how module oriented Magento is, it seems like this is doing it wrong.

我意识到我可以在库中使用 custo 自动加载器或符号链接,但我主要想了解是否有

I realize I could jank around with a custo autoloader or symlinks in the lib, but I'm primarily interested in learning if there's

  1. 为属性添加自定义表单元素的规范方法

  1. A canonical way to add custom form elements for attributes

自定义 Magento 自动加载器的规范方法.

A canonical way to customize the Magento autoloader.

推荐答案

自助服务台再次罢工.看起来 Magento 设置包含路径的方式是,您可以从本地代码分支中的 lib(不仅仅是 Mage_ 命名空间)中删除类文件

Self help desk strikes again. It looks like Magento sets up include paths in such a way that you can drop class files from lib (not just from the Mage_ namespace) in your local code branch

app/code/local/Varien/etc

当自动加载器尝试加载 lib/Varien 类时,它会首先检查您的目录.如果 Varien 创建了与您同名的数据元素,这仍然会使您面临风险,但随着风险的增加,风险相对较低.

When the autoloader tries to load a lib/Varien class, it will check your directory first. This still puts you at risk if Varien ever creates a data element with the same name as yours, but as risks go it's relatively low.

这篇关于将自定义表单元素添加到 Adminhtml 表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆