Home > Back-end >  Drupal 8 add image field to content type programatically
Drupal 8 add image field to content type programatically

Time:09-25

Im tried to add image field to custom content type(shop) via module. And image storage yml (field.storage.node.field_exp_image.yml) as follows

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

and updated core.entity_form_display.node.shop.default to add image field to shop content type

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: {  }

i got following error

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

CodePudding user response:

You need to define the field config by creating file field.field.node.shop.field_exp_image.yml. An example of the field config file structure: https://github.com/drupal/drupal/blob/8.9.x/core/profiles/standard/config/install/field.field.user.user.user_picture.yml

  • Related