Ich habe programmgesteuert ein Benutzerfeld hinzugefügt, aber ich kann keine Möglichkeit finden, das Feld unter "Formularanzeige verwalten" und "Anzeige verwalten" programmgesteuert zu aktivieren.
Ich habe versucht, die unten gezeigten Konfigurationen "Entity View Display" und "Entity Form Display" zu exportieren, kann das Modul jedoch nicht mit dieser Methode installieren
Anzeige des Entitätsformulars:
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: { }
Anzeige der Entitätsansicht:
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: { }
Gibt es eine Möglichkeit, dies in Drupal 8 zu tun?
Ich habe versucht, die vorhandenen Felder damit zu bearbeiten, aber es hat nicht funktioniert:
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();
}
Antworten:
Sie können keine bereits vorhandenen Ansichts- oder Formularmodi installieren. Sie könnten versuchen, sie zu überschreiben, indem Sie das yaml analysieren und den gesamten Inhalt in der Konfiguration speichern. Ein besserer Ansatz wäre jedoch, nur die neuen Felder hinzuzufügen, um alle Änderungen beizubehalten, die der Websitebesitzer möglicherweise vorgenommen hat.
Sie können Felder mit setComponent () in der Konfiguration des Ansichtsmodus hinzufügen:
oder Formularmodus:
Beispiel
core.entity_view_display.user.user.default.yml
PHP
Wenn Sie kein Gewicht festlegen, wird das Feld unter dem letzten Feld angehängt.
quelle