如何在 ExpressionEngine 2.x 中的发布表单上添加新选项卡

发布于 2024-10-06 08:42:49 字数 189 浏览 0 评论 0原文

我正在编写一个在提交条目时调用的扩展。
现在我想在发布中添加一个包含几个字段的选项卡?

我可以从扩展中执行此操作吗?

我知道有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

滥情哥ㄟ 2024-10-13 08:42:49

2.x 模块 API 允许这样做。此处的文档:http://expressionengine.com/user_guide/development/modules.html

可以将相同类型的模块和扩展与如下结构组合起来:

/system/expressionengine/third_party/addon_name/
    ext.addon_name.php
    language/
        english/
            lang.addon_name.php
    mcp.addon_name.php
    mod.addon_name.php
    tab.addon_name.php # Add fields to tab here, per API spec
    upd.addon_name.php # Add/remove tab here, per API spec

当用户安装扩展或模块时,系统会自动询问他们是否要同时安装两者。显然,如果目的只是向发布者添加选项卡/字段,则您的 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:

/system/expressionengine/third_party/addon_name/
    ext.addon_name.php
    language/
        english/
            lang.addon_name.php
    mcp.addon_name.php
    mod.addon_name.php
    tab.addon_name.php # Add fields to tab here, per API spec
    upd.addon_name.php # Add/remove tab here, per API spec

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.

命比纸薄 2024-10-13 08:42:49

要补充第一个答案,

我经常遇到的问题是没有在模块的更新文件中的任何位置调用 add_layout_tabs 方法(即以 upd.< 开头的文件)。 /code>)

所以假设您的更新文件名为:upd.addon_name.php。然后在 install 中看起来像这样(注意:以下函数都是更新文件中 Addon_name_upd 类的一部分:

function install () {

  // ... create databases or any necessary code for your module

  $this->EE->load->library('layout');
  $this->EE->layout->add_layout_tabs($this->tabs(), 'addon_name');

  return TRUE;
}

注意对 $this-> 的调用;tabs() 方法:该方法看起来像这样:

function tabs() {
  $tabs['addon_name'] = array(
    'field_1_inside_publish_form' => array(
    'visible'   => 'true',
    'collapse'=> 'false',
    'htmlbuttons'   => 'true',
    'width' => '100%'
    )
  );

  return $tabs;
}

其中 field_1_inside_publish_form 是在模块的相应选项卡文件中定义的字段(即 tab.addon_name. 。

安装方法实际上会将新选项卡保存到包含模块选项卡配置的现有发布布局中,

但是,您必须通过调用在更新文件的卸载方法中添加一个方法来删除配置 delete_layout_tabs 方法如下:

function uninstall() {

  // necessary code to drop your database tables or whatever

 $this->EE->load->library('layout');
 $this->EE->layout->delete_layout_tabs($this->tabs(), 'addon_name');

 return TRUE;

} 

还有一件事,如果你像我一样开发:在这里做一点更改,测试你的更改,返回并编写更多代码,然后你会发现如果有新字段启用模块后添加到选项卡文件 tab.addon_name.php 的内容不会出现在发布页面上的新选项卡中,原因是 add_layout_tabs 方法。您调用需要运行的更新文件的安装方法。

但是,只有当您启用模块时才会执行此方法。因此,这意味着您必须禁用您的模块,如果您的模块添加了数据库表,这将是一个拖累。幸运的是,您可以使更新文件的更新方法加载新的选项卡配置(除了添加或删除任何新的数据库表作为模块更新的一部分之外)。

其想法是删除以前的配置并添加配置,其中,调用您的 tabs 方法,该方法具有模块选项卡部分的新字段的名称。

因此,假设您的 tabs 方法有一个名为 'field_2_inside_publish_form' 的新字段,如下所示:

function tabs() {
 $tabs['addon_name'] = array(
    'field_1_inside_publish_form' => array(
    'visible'   => 'true',
    'collapse'=> 'false',
    'htmlbuttons'   => 'true',
    'width' => '100%'
   ),
   'field_2_inside_publish_form' => array(
    'visible'   => 'true',
    'collapse'=> 'false',
    'htmlbuttons'   => 'true',
    'width' => '100%'
   )
 );   
}

那么您的更新方法可以像这样更新布局(假设您已更新了 $this->version 属性udpate 文件从“1.0”更改为“1.5”。

function update($current='') {
  // don't do anything if the version hasn't changed
  if($current == $this->version) {  
    return FALSE;
  }

  // the version property has  a version higher than current version in db
  // this means the module is being updated.
  if($current < $this->version) {
    // update the tab layout

    // delete old layout
    $this->EE->load->library('layout');
    $this->EE->layout->delete_layout_tabs($this->tabs(), 'addon_name');

    // add new tab layout which calls tabs method with updated code
    $this->EE->load->library('layout');
    $this->EE->layout->add_layout_tabs($this->tabs(), 'addon_name');

  }
  return TRUE;
}   

请记住,每次进入模块控制面板页面时,模块更新文件的更新方法都会在模块控制面板页面中定义。 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 with upd.)

So suppose your update file is called: upd.addon_name.php. Then in the install looks like this (note: the following functions are all part of the Addon_name_upd class inside your update file:

function install () {

  // ... create databases or any necessary code for your module

  $this->EE->load->library('layout');
  $this->EE->layout->add_layout_tabs($this->tabs(), 'addon_name');

  return TRUE;
}

Notice the call to $this->tabs() method: That method looks something like this:

function tabs() {
  $tabs['addon_name'] = array(
    'field_1_inside_publish_form' => array(
    'visible'   => 'true',
    'collapse'=> 'false',
    'htmlbuttons'   => 'true',
    'width' => '100%'
    )
  );

  return $tabs;
}

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:

function uninstall() {

  // necessary code to drop your database tables or whatever

 $this->EE->load->library('layout');
 $this->EE->layout->delete_layout_tabs($this->tabs(), 'addon_name');

 return TRUE;

} 

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 method add_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:

function tabs() {
 $tabs['addon_name'] = array(
    'field_1_inside_publish_form' => array(
    'visible'   => 'true',
    'collapse'=> 'false',
    'htmlbuttons'   => 'true',
    'width' => '100%'
   ),
   'field_2_inside_publish_form' => array(
    'visible'   => 'true',
    'collapse'=> 'false',
    'htmlbuttons'   => 'true',
    'width' => '100%'
   )
 );   
}

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'.

function update($current='') {
  // don't do anything if the version hasn't changed
  if($current == $this->version) {  
    return FALSE;
  }

  // the version property has  a version higher than current version in db
  // this means the module is being updated.
  if($current < $this->version) {
    // update the tab layout

    // delete old layout
    $this->EE->load->library('layout');
    $this->EE->layout->delete_layout_tabs($this->tabs(), 'addon_name');

    // add new tab layout which calls tabs method with updated code
    $this->EE->load->library('layout');
    $this->EE->layout->add_layout_tabs($this->tabs(), 'addon_name');

  }
  return TRUE;
}   

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 the Addon_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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文