Drupal 8 以编程方式将图像字段添加到内容类型

Drupal 8 add image field to content type programatically

我试图通过模块将图像字段添加到自定义内容类型(商店)。以及图片存储yml(field.storage.node.field_exp_image.yml)如下

langcode: en
status: true
dependencies:
  module:
    - file
    - image
    - node
id: node.field_exp_image
field_name: field_exp_image
entity_type: node
type: image
settings:
  uri_scheme: public
  default_image:
    uuid: null
    alt: ''
    title: ''
    width: null
    height: null
  target_type: file
  display_field: false
  display_default: false
module: image
locked: false
cardinality: 1
translatable: true
indexes:
  target_id:
    - target_id
persist_with_no_fields: false
custom_storage: false

并更新了 core.entity_form_display.node.shop.default 以将图像字段添加到商店内容类型

langcode: en
status: true
dependencies:
    config:
        - field.field.node.shop.body
        - field.field.node.shop.field_exp_image
        - node.type.shop
    module:
        - text
        - user
id: node.shop.default
targetEntityType: node
bundle: shop
mode: default
content:
    body:
        label: hidden
        type: text_textarea_with_summary
        weight: 101
        settings: {  }
        third_party_settings: {  }
           
       field_exp_image:
         type: image
         settings:{}
         third_party_settings: {  }
         weight: 6        
       links:
           weight: 100
hidden: {  }

我遇到以下错误

Unable to install shopwiz due to unmet dependencies: core.entity_form_display.node.shop.default (field.field.node.shop.field_exp_image)

您需要通过创建文件field.field.node.shop.field_exp_image.yml来定义字段配置。 字段配置文件结构示例:https://github.com/drupal/drupal/blob/8.9.x/core/profiles/standard/config/install/field.field.user.user.user_picture.yml