プログラムでユーザーフィールドを追加しましたが、[フォームの表示の管理]と[表示の管理]でプログラムによってフィールドを有効にする方法が見つかりません。
以下のように「エンティティビュー表示」と「エンティティフォーム表示」の設定をエクスポートしてみましたが、この方法を使用してモジュールをインストールできません
エンティティフォームの表示:
uuid: ecd2bd45-26ec-4fee-835a-eedc20a1dbf9
langcode: en
status: true
dependencies:
config:
- field.field.user.user.field_birthdate_pixelpin
- field.field.user.user.field_country_pixelpin
- field.field.user.user.field_family_name_pixelpin
- field.field.user.user.field_gender_pixelpin
- field.field.user.user.field_given_name_pixelpin
- field.field.user.user.field_nickname_pixelpin
- field.field.user.user.field_phone_number_pixelpin
- field.field.user.user.field_postal_code_pixelpin
- field.field.user.user.field_region_pixelpin
- field.field.user.user.field_street_address_pixelpin
- field.field.user.user.field_town_city_pixelpin
- field.field.user.user.user_picture
- image.style.thumbnail
module:
- image
- user
_core:
default_config_hash: LLAieeozVsoZDb-2PbFxRJpQqnKmpR7-4OoRJnduz-U
id: user.user.default
targetEntityType: user
bundle: user
mode: default
content:
account:
weight: 0
settings: { }
third_party_settings: { }
contact:
weight: 3
settings: { }
third_party_settings: { }
field_birthdate_pixelpin:
type: string_textfield
weight: 5
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_country_pixelpin:
type: string_textfield
weight: 6
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_family_name_pixelpin:
type: string_textfield
weight: 7
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_gender_pixelpin:
type: string_textfield
weight: 8
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_given_name_pixelpin:
type: string_textfield
weight: 9
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_nickname_pixelpin:
type: string_textfield
weight: 10
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_phone_number_pixelpin:
type: string_textfield
weight: 11
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_postal_code_pixelpin:
type: string_textfield
weight: 12
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_region_pixelpin:
type: string_textfield
weight: 13
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_street_address_pixelpin:
type: string_textfield
weight: 14
settings:
size: 60
placeholder: ''
third_party_settings: { }
field_town_city_pixelpin:
type: string_textfield
weight: 15
settings:
size: 60
placeholder: ''
third_party_settings: { }
language:
weight: 2
settings: { }
third_party_settings: { }
timezone:
weight: 4
settings: { }
third_party_settings: { }
user_picture:
type: image_image
settings:
progress_indicator: throbber
preview_image_style: thumbnail
third_party_settings: { }
weight: 1
hidden: { }
エンティティビューの表示:
uuid: 7ae755fd-5988-446f-beb5-2c9725b10c30
langcode: en
status: true
dependencies:
config:
- field.field.user.user.field_birthdate_pixelpin
- field.field.user.user.field_country_pixelpin
- field.field.user.user.field_family_name_pixelpin
- field.field.user.user.field_gender_pixelpin
- field.field.user.user.field_given_name_pixelpin
- field.field.user.user.field_nickname_pixelpin
- field.field.user.user.field_phone_number_pixelpin
- field.field.user.user.field_postal_code_pixelpin
- field.field.user.user.field_region_pixelpin
- field.field.user.user.field_street_address_pixelpin
- field.field.user.user.field_town_city_pixelpin
- field.field.user.user.user_picture
- image.style.thumbnail
module:
- image
- user
_core:
default_config_hash: L2mtwGWH_7wDRCMIR4r_Iu_jmvQ10DV1L8ht8iNZ5qY
id: user.user.default
targetEntityType: user
bundle: user
mode: default
content:
field_birthdate_pixelpin:
type: string
weight: 2
label: above
settings:
link_to_entity: false
third_party_settings: { }
field_country_pixelpin:
type: string
weight: 3
label: above
settings:
link_to_entity: false
third_party_settings: { }
field_family_name_pixelpin:
type: string
weight: 4
label: above
settings:
link_to_entity: false
third_party_settings: { }
field_gender_pixelpin:
type: string
weight: 5
label: above
settings:
link_to_entity: false
third_party_settings: { }
field_given_name_pixelpin:
type: string
weight: 6
label: above
settings:
link_to_entity: false
third_party_settings: { }
field_nickname_pixelpin:
type: string
weight: 7
label: above
settings:
link_to_entity: false
third_party_settings: { }
field_phone_number_pixelpin:
type: string
weight: 8
label: above
settings:
link_to_entity: false
third_party_settings: { }
field_postal_code_pixelpin:
type: string
weight: 9
label: above
settings:
link_to_entity: false
third_party_settings: { }
field_region_pixelpin:
type: string
weight: 10
label: above
settings:
link_to_entity: false
third_party_settings: { }
field_street_address_pixelpin:
type: string
weight: 11
label: above
settings:
link_to_entity: false
third_party_settings: { }
field_town_city_pixelpin:
type: string
weight: 12
label: above
settings:
link_to_entity: false
third_party_settings: { }
member_for:
weight: 1
settings: { }
third_party_settings: { }
user_picture:
type: image
weight: 0
settings:
image_style: thumbnail
image_link: content
third_party_settings: { }
label: hidden
hidden: { }
Drupal 8でこれを行う方法はありますか?
これを使用して既存のフィールドを編集しようとしましたが、うまくいきませんでした:
function openid_connet_entity_edit(){
\Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('user.user.default')
->setComponent('field_birthdate_pixelpin', [
'format' => 'plain text'
])->save();
\Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load('user.user.default')
->setComponent('field_birthdate_pixelpin', [
'Widget' => 'textfield'
])->save();
}
すでに存在するビューモードまたはフォームモードをインストールすることはできません。 yamlを解析して完全なコンテンツを構成に保存することでそれらを上書きしようとすることもできますが、より良いアプローチは、サイト所有者が行った可能性のある変更を保存するために新しいフィールドのみを追加することです。
表示モードの構成でsetComponent()を使用してフィールドを追加できます。
\Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('user.user.default')
->setComponent('field_example', [
'label' => 'hidden',
'type' => 'string',
'settings' => ['...' => '...'],
])->save();
またはフォームモード:
\Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load('user.user.default')
->setComponent('field_example', [
...
例
core.entity_view_display.user.user.default.yml
content:
field_birthdate_pixelpin:
type: string
weight: 2
label: above
settings:
link_to_entity: false
third_party_settings: { }
PHP
\Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('user.user.default')
->setComponent('field_birthdate_pixelpin', [
'type' => 'string',
'label' => 'above',
'settings' => ['link_to_entity' => 'false'],
])->save();
ウェイトを設定しない場合、フィールドは最後のフィールドの下に追加されます。