如何在October CMS中动态更改“表单”选项卡标题

时间:2018-10-25 04:03:42

标签: octobercms octobercms-backend

在10月的CMS后端中,是否有一种有效的方法或插件可以动态更改“表单”选项卡的标题?

类似于从Builder插件完成的方式,但更加用户友好: enter image description here

1 个答案:

答案 0 :(得分:0)

您可以收听backend.form.extendFieldsBefore事件。您可以将其与数据库中的数据提取结合起来,并在此处使用(可能由某些用户输入..)

  

在插件的启动方法中写下来。

<?php

class Plugin extends PluginBase
{
    public function boot() {

      \Event::listen('backend.form.extendFieldsBefore', function($widget) {

          if (!$widget->model instanceof \RainLab\User\Models\User) {
              // --------------------------------- ^ Check if its your modal 
              return; // other wise do nothing return
          }

          // rainlab.user::lang.user.account => 
          // translated to Account by Lang Manager

          // need to change  
          // "rainlab.user::lang.user.account" => 'My Account - OK'
          // if you need to change tab's title
          // you need to change it for all fields
          // which uses that same tab title

          foreach ($widget->tabs['fields'] as $key => $val) {
            if($val['tab'] === 'rainlab.user::lang.user.account') {
              $widget->tabs['fields'][$key]['tab'] = 'My Account - OK';
            }
          }

      });

    ...
}
  

先于结果

enter image description here

  

结果之后

enter image description here 如有任何疑问,请发表评论

相关问题