将自定义表单元素添加到 Adminhtml 表单

编程入门 行业动态 更新时间:2024-10-12 03:26:30
本文介绍了将自定义表单元素添加到 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

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

  • 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 表单

    本文发布于:2023-11-28 17:38:53,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1643340.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:表单   自定义   元素   Adminhtml

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!