0

I have created a drupal8 module that programmatically created custom user fields. It display in Manage fields section but not enable/view inside Manage form display and Manage display section.

I have tried to override entiry_form_display but not get success.

core.entity_form_display.user.facebook.default.yml

langcode: en
status: true
dependencies:
  config:
    - field.field.user.user.field_facebook
  module:
    - field_layout
    - layout_discovery
    - user
id: user.field_facebook.default
targetEntityType: user
bundle: field_facebook
mode: default
content:
  field_facebook:
    type: string
    weight: 200
    label: above
    settings:
      link_to_entity: false
    third_party_settings: {  }
hidden: {  }

field.field.user.user.field_facebook.yml

langcode: en
status: true
dependencies:
  config:
    - field.storage.user.field_facebook
  module:
    - user
id: user.user.field_facebook
field_name: field_facebook
entity_type: user
bundle: user
label: 'Facebook'
description: ''
required: false
translatable: false
default_value: {  }
default_value_callback: ''
settings: {  }
field_type: string

field.storage.user.field_fullcontact_facebook.yml

langcode: en
status: true
dependencies:
  module:
    - user
id: user.field_facebook
field_name: field_facebook
entity_type: user
type: string
settings: { 
  max_length: 255
  is_ascii: false
  case_sensitive: false
 }
module: core
locked: false
cardinality: 1
translatable: true
indexes: {  }
persist_with_no_fields: false
custom_storage: false
Durgesh
  • 97
  • 3
  • 8

2 Answers2

0

persist_with_no_fields: true

Give it a try.

Sibil
  • 107
  • 8
  • The `persist_with_no_fields` is a boolean flag that determines whether to persist field storage configurations even if there are no fields associated with it. When `persist_with_no_fields` is set to `TRUE`, the field storage configuration will be stored in the configuration management system, even if there are no fields associated with it. This means that the configuration will be exportable and can be deployed to other environments, even if there are no fields currently using it. – Alen Simonyan Apr 13 '23 at 10:12
0

For enabling custom field under manage form display programmatically you will need to set hidden property to FALSE for field in EntityFormDisplay configuration, here is how.

$form_display = EntityFormDisplay::load('user.' . 'facebook' . '.default');
if (!$form_display) {
  $form_display = EntityFormDisplay::create([
    'targetEntityType' => 'user',
    'bundle' => 'facebook',
    'mode' => 'default',
    'status' => TRUE,
  ])->setComponent('field_facebook', [
    'region' => 'content',
    'type' => 'string_textfield',
    'weight' => 5,
    'hidden' => FALSE,
  ])
  ->save();
}
Alen Simonyan
  • 360
  • 2
  • 9