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

查看:96
本文介绍了将自定义表单元素添加到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 autoloader或符号链接来解决问题,但是我主要是想了解是否有

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天全站免登陆