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

How to dynamically change Form Tab Titles in October CMS

是否有有效的方法或插件可以在 October CMS 后端动态更改表单选项卡的标题?

类似于从 Builder 插件完成的方式,但更多 user-friendly: enter image description here

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

Write down this in your plugin's boot method.

<?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';
            }
          }

      });

    ...
}

before result

after result

如有疑问请评论