如何在 ExpressionEngine 2.x 中的发布表单上添加新选项卡
我正在编写一个在提交条目时调用的扩展。
现在我想在发布中添加一个包含几个字段的选项卡?
我可以从扩展中执行此操作吗?
我知道有 EE1.x 挂钩 - publish_form_new_tabs、publish_form_new_tabs_block
....
但我需要这个用于 EE 2.x
I’m writing an extension that called when an entry is submitted.
Now i want to add a tab with few fields in publish from?
Can i do this from extension?
I know there are EE1.x hooks - publish_form_new_tabs, publish_form_new_tabs_block
....
but i need this for EE 2.x
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
2.x 模块 API 允许这样做。此处的文档:http://expressionengine.com/user_guide/development/modules.html
可以将相同类型的模块和扩展与如下结构组合起来:
当用户安装扩展或模块时,系统会自动询问他们是否要同时安装两者。显然,如果目的只是向发布者添加选项卡/字段,则您的 mcp 和 mod 类可能只是成功安装模块所需的最低限度。
希望这是一个好的起点。
The 2.x module API allows this. Documentation here: http://expressionengine.com/user_guide/development/modules.html
You can combine a module and extension of the same type with a structure like this:
When a user installs either the extension or module, they'll be asked automatically if they want to install both at the same time. Obviously if the purpose is just to add a tab/fields to the publisher, your mcp and mod classes may be just the minimum needed to successfully install a module.
Hope this is a good starting point.
要补充第一个答案,
我经常遇到的问题是没有在模块的更新文件中的任何位置调用
add_layout_tabs
方法(即以upd.< 开头的文件)。 /code>)
所以假设您的更新文件名为:
upd.addon_name.php
。然后在install
中看起来像这样(注意:以下函数都是更新文件中Addon_name_upd
类的一部分:注意对
$this-> 的调用;tabs()
方法:该方法看起来像这样:其中
field_1_inside_publish_form
是在模块的相应选项卡文件中定义的字段(即tab.addon_name. 。
安装方法实际上会将新选项卡保存到包含模块选项卡配置的现有发布布局中,
但是,您必须通过调用在更新文件的卸载方法中添加一个方法来删除配置
delete_layout_tabs
方法如下:还有一件事,如果你像我一样开发:在这里做一点更改,测试你的更改,返回并编写更多代码,然后你会发现如果有新字段启用模块后添加到选项卡文件
tab.addon_name.php
的内容不会出现在发布页面上的新选项卡中,原因是add_layout_tabs
方法。您调用需要运行的更新文件的安装方法。但是,只有当您启用模块时才会执行此方法。因此,这意味着您必须禁用您的模块,如果您的模块添加了数据库表,这将是一个拖累。幸运的是,您可以使更新文件的更新方法加载新的选项卡配置(除了添加或删除任何新的数据库表作为模块更新的一部分之外)。
其想法是删除以前的配置并添加配置,其中,调用您的 tabs 方法,该方法具有模块选项卡部分的新字段的名称。
因此,假设您的 tabs 方法有一个名为 'field_2_inside_publish_form' 的新字段,如下所示:
那么您的更新方法可以像这样更新布局(假设您已更新了
$this->version
属性udpate 文件从“1.0”更改为“1.5”。请记住,每次进入模块控制面板页面时,模块更新文件的更新方法都会在模块控制面板页面中定义。
mcp.addon_name.php
)。您的模块的主控制面板页面可能对应于您的控制面板页面文件的Addon_name_mcp
类的索引方法。文件(即 对应于这样的链接 uri:
admin.php?S=0&D=cp&C=addons_modules&M=show_module_cp&module=addon_name&method=index
希望这有点长。啰嗦,但我写它更多的是为了我自己的利益而不是为了其他人(因为我浪费了大约 3 个小时试图让我的模块工作。)
To add to the first answer,
one thing that I constantly had problems with is not calling the
add_layout_tabs
method anywhere in the update file of your module (i.e .the file that starts withupd.
)So suppose your update file is called:
upd.addon_name.php
. Then in theinstall
looks like this (note: the following functions are all part of theAddon_name_upd
class inside your update file:Notice the call to
$this->tabs()
method: That method looks something like this:Where
field_1_inside_publish_form
is a field that would be defined in your corresponding tab file for the module (i.e.tab.addon_name.php
).The install method will in effect save a new tab to the existing publish layout that includes your module's tab configuration.
However, you must add a method to remove your configuration in the uninstall method of the update file by calling the
delete_layout_tabs
method like so:One more thing, if you develop like I do: make a little change here, test your change, go back and code some more, then you'll find that if new fields added to the tab file
tab.addon_name.php
after your module is enabled don't appear in your new tab on the publish page. The reason is because the methodadd_layout_tabs
that you call in the install method of your update file needs to be ran.However, this method only gets executed when you enable your module. So that means you have to disable your module, which is a drag if your module adds database tables. Luckily you can make the update method of your update file load your new tab configuration (in addition to adding or dropping any new database tables as part of your module's updates.)
The idea is that you delete your previous configuration and you add the configuration, which, calls your tabs method which has the names of the the new fields for your module's tab section.
So, suppose your tabs method has a new field called 'field_2_inside_publish_form' like so:
then your update method can update the layout like so (assume that you've updated your
$this->version
property in the udpate file from '1.0' to '1.5'.Remember that the update method of the update file of your module gets run everytime you are in your module's control panel page defined in in your modules control panel page file (i.e.
mcp.addon_name.php
). Your module's main control panel page would probably correspond to the index method of theAddon_name_mcp
class of your control panel page file.It would correspond to a link uri like this:
admin.php?S=0&D=cp&C=addons_modules&M=show_module_cp&module=addon_name&method=index
Hope that helps. It's kind of long winded but I wrote it more for my own benefit than for anyone else (cause I wasted like 3 hours trying to get my module to work.)