追加/更新が(デフォルトで)Magentoユーザーの(モジュール-ユーザー)フォームを既に準備している良いアプローチを探しています。フォームには、次のパスで管理パネルにアクセスできます。
システム>すべてのユーザー> [chosen_user]>ユーザーのメイン編集タブ(アカウント情報)
次に、依存関係を指定するカスタムモジュールでdi.xmlを使用してみます。`
<preference for="Magento\User\Block\User\Edit\Tab\Main" type="Vendor_Name\Module_Name\Block\User\Edit\Tab\Main" />
<preference for="Magento\User\Block\Role\Grid\User" type="Vendor_Name\Module_Name\Block\Role\Grid\User" />
`
これは、Main.phpクラス用にすでに作成したコンテンツです
// @codingStandardsIgnoreFile
名前空間Vendor_Name \ Module_Name \ Block \ User \ Edit \ Tab;
\ Magento \ User \ Block \ User \ Edit \ Tab \ MainをUserEditMainTabとして使用します。
\ Magento \ Backend \ Block \ Template \ Contextを使用します。
\ Magento \ Framework \ Registryを使用します。
\ Magento \ Framework \ Data \ FormFactoryを使用します。
\ Magento \ Backend \ Model \ Auth \ Sessionを使用します。
\ Magento \ Framework \ Locale \ ListsInterfaceを使用します。
MainクラスはUserEditMainTabを拡張します
{
パブリック関数__construct(
コンテキスト$ context、
レジストリ$ registry、
FormFactory $ formFactory、
セッション$ authSession、
ListsInterface $ localeLists、
配列$ data = []
){
parent :: __ construct($ context、$ registry、$ formFactory、$ authSession、$ localeLists、$ data);
}
保護された関数_prepareForm()
{
/ ** @var $ model \ Magento \ User \ Model \ User * /
$ model = $ this-> _ coreRegistry-> registry( 'permissions_user');
/ ** @var \ Magento \ Framework \ Data \ Form $ form * /
$ form = $ this-> _ formFactory-> create();
$ form-> setHtmlIdPrefix( 'user_');
$ baseFieldset = $ form-> addFieldset( 'base_fieldset'、['legend' => __( 'Account Information __ TEST')]);
if($ model-> getUserId()){
$ baseFieldset-> addField( 'user_id'、 'hidden'、['name' => 'user_id']);
} そうしないと {
if(!$ model-> hasData( 'is_active')){
$ model-> setIsActive(1);
}
}
$ baseFieldset-> addField(
'user_image'、
'画像'、
[
'名前' => 'ユーザー画像'、
'ラベル' => __( 'ユーザー画像')、
'id' => 'user_image'、
'title' => __( 'User Image')、
'必須' => false、
'note' => 'Allow image type:jpg、jpeg、png'
]
);
$ baseFieldset-> addField(
'ユーザー名'、
'テキスト'、
[
'名前' => 'ユーザー名'、
'ラベル' => __( 'ユーザー名')、
'id' => 'ユーザー名'、
'title' => __( 'ユーザー名')、
'必須' => true
]
);
$ baseFieldset-> addField(
'ファーストネーム'、
'テキスト'、
[
'名前' => '名'、
'ラベル' => __( '名')、
'id' => 'firstname'、
'title' => __( 'First Name')、
'必須' => true
]
);
$ baseFieldset-> addField(
'苗字'、
'テキスト'、
[
'名前' => '姓'、
'ラベル' => __( '姓')、
'id' => '姓'、
'title' => __( '姓')、
'必須' => true
]
);
$ baseFieldset-> addField(
'Eメール'、
'テキスト'、
[
'名前' => 'メール'、
'ラベル' => __( 'メール')、
'id' => 'customer_email'、
'title' => __( 'User Email')、
'class' => 'required-entry validate-email'、
'必須' => true
]
);
$ isNewObject = $ model-> isObjectNew();
if($ isNewObject){
$ passwordLabel = __( 'Password');
} そうしないと {
$ passwordLabel = __( '新しいパスワード');
}
$ confirmationLabel = __( 'パスワードの確認');
$ this-> _ addPasswordFields($ baseFieldset、$ passwordLabel、$ confirmationLabel、$ isNewObject);
$ baseFieldset-> addField(
'interface_locale'、
'選択する'、
[
'name' => 'interface_locale'、
'label' => __( 'Interface Locale')、
'title' => __( 'Interface Locale')、
'values' => $ this-> _ LocaleLists-> getTranslatedOptionLocales()、
'クラス' => '選択'
]
);
if($ this-> _ authSession-> getUser()-> getId()!= $ model-> getUserId()){
$ baseFieldset-> addField(
'アクティブです'、
'選択する'、
[
'名前' => 'is_active'、
'label' => __( 'このアカウントは')、
'id' => 'is_active'、
'title' => __( 'アカウントステータス')、
'クラス' => '入力選択'、
'オプション' => ['1' => __( 'アクティブ')、 '0' => __( '非アクティブ')]
]
);
}
$ baseFieldset-> addField( 'user_roles'、 'hidden'、['name' => 'user_roles'、 'id' => '_user_roles']);
$ currentUserVerificationFieldset = $ form-> addFieldset(
'current_user_verification_fieldset'、
['legend' => __( 'Current User Identity Verification')]
);
$ currentUserVerificationFieldset-> addField(
self :: CURRENT_USER_PASSWORD_FIELD、
'パスワード'、
[
'名前' => self :: CURRENT_USER_PASSWORD_FIELD、
'ラベル' => __( 'あなたのパスワード')、
'id' => self :: CURRENT_USER_PASSWORD_FIELD、
'title' => __( 'あなたのパスワード')、
'class' => 'input-text validate-current-password required-entry'、
'必須' => true
]
);
$ data = $ model-> getData();
unset($ data ['password']);
unset($ data [self :: CURRENT_USER_PASSWORD_FIELD]);
$ form-> setValues($ data);
$ this-> setForm($ form);
parent :: _ prepareForm();を返します。
}
}
User.phpのコード
名前空間Vendor_Name \ Module_Name \ Block \ Role \ Grid;
RoleGridUserとして\ Magento \ User \ Block \ Role \ Grid \ Userを使用します。
ExtendedGridとして\ Magento \ Backend \ Block \ Widget \ Grid \ Extendedを使用します。
クラスUserはRoleGridUserを拡張します
{
保護された関数_prepareColumns()
{
parent :: _ prepareCollection();
$ this-> addColumn(
'user_image'、
[
'header' => __( 'User Image')、
'幅' => 5
'align' => 'left'、
'sortable' => true、
'インデックス' => 'user_image'
]
);
ExtendedGrid :: _ prepareCollection();を返します。
}
}
よく見てみると、ユーザーの画像を含むフィールドを追加しようとしていることがわかります。
残念ながら、私は管理画面で何の変更も見ていません。もちろん、必要な列はInstallSchemaスクリプトによって以前に ' admin_user 'テーブルに追加されました。
ツリーのような形式のディレクトリの内容:
Module_Name ├──ブロック │├──カタログ ││└───製品 ││└──RelatedPosts.php │├──役割 ││└──グリッド ││└──User.php │└──ユーザー │└──編集 │└──タブ │└──Main.php ├──composer.json ├──など │├──di.xml │└──module.xml ├──セットアップ └──InstallSchema.php
何を間違えたか