2017-07-08 18 views
1

RainLab Userプラグインを拡張しようとしており、バックエンドフォームのフィールドをフィルタリングする必要があります。OctoberCMS - プラグインを拡張するfilterFieldsメソッド

Userモデルを直接編集すると、機能するようになりますが、自分のプラグイン登録ファイルから "addDynamicMethod"を使って運がないとします。 Userモデルファイルの コード:以下

public function filterFields($fields, $context = null) 
{ 
    if (property_exists($fields, 'usertype')) { 

     $userType = $fields->usertype->value; 

     if($userType == $this->AGENT || $userType == null) { 
      $fields->agent->hidden = true; 
     } 
    } 
} 

答えて

1

は、私は私のバックエンド・ユーザー・プラグインを拡張するために、私のカスタムプラグインの1で行ったサンプルコードです。カスタムプラグインのboot()関数に以下のようなロジックを入れることができます。

use Backend\Models\User as BackendUserModel; 
public function boot() 
{ 
    // Add Team field in user administartor form 
    BackendUsersController::extendFormFields(function($form, $model, $context){ 

     if (!$model instanceof BackendUserModel) 
      return; 

     $form->addTabFields([ 
      'team' => [ 
       'label' => 'Team', 
       'comment' => 'Associate this user with a team.', 
       'type' => 'recordfinder', 
       'list' => '$/technobrave/team/models/team/columns.yaml', 
       'prompt' => 'Click the %s to find a team', 
       'select' => 'id', 
       'nameFrom'=> 'name', 
       'tab' => 'Account', 
       'disabled' => true      
      ] 
     ]); 
    }); 
} 

上記の機能では、ユーザーの更新フィールドを無効にしました。

上記のコードを参考にして、必要に応じて回避することができます。

これが役に立ちます。

関連する問題