【问题标题】:Drupal 8 add image field to content type programaticallyDrupal 8 以编程方式将图像字段添加到内容类型
【发布时间】:2021-11-15 15:34:30
【问题描述】:

我尝试通过模块将图像字段添加到自定义内容类型(商店)。和图片存储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: {  }

我收到以下错误

由于未满足依赖关系,无法安装 shopwiz: core.entity_form_display.node.shop.default (field.field.node.shop.field_exp_image)

【问题讨论】:

    标签: image drupal-8 content-type


    【解决方案1】:

    您需要通过创建文件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

    【讨论】:

      猜你喜欢
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2015-12-27
      • 2013-11-08
      • 1970-01-01
      • 2016-03-19
      相关资源
      最近更新 更多