0

I need to add 2 fields to an existing content type in Drupal 8 website, one is text another is file type, I have a multisite setup so I need to add for every locale site, Now I have created a module and created installer file, right now I am able to create the fields but I am unable to add the file extension to the file type field. can anyone please help with this?

I have followed this below documentation to create the filed.

https://www.drupal.org/docs/8/api/entity-api/programming-custom-fields-into-your-content-type

  • Why can’t you just add the fields in the interface, and then export configuration? – Jdrupal May 22 at 6:51
1

Really, that's a task for the Features module. And even if you decide against fully using Features in the end, you could at least use it locally to export your content type and fields and see in the resulting installer files how the allowed file extensions needs to be defined in your own module then. As Features exports its config into ready-made modules. But going for fully using Features also will enable you to constantly sync certain config (content types, fields, image styles etc.) pretty easily across all your multisite instances.

  1. Take one of your multisite instances where you have the content type like you want it to be on all other sites.
  2. Go through Features' UI and create a features module from it (that's called "package", usually that goes under /modules/features/my_package).
  3. Activate the resulting package (module) on all other instances.

Leaving the Features module and your package module activated on all instances now allows you to sync all following changes to your content type by a certain set of commands:

# In the site_foo instance export changes into its package module.
drush -y features:export my_package -l site_foo

# In the site_bar instance import the changes.
drush -y features:import:all --bundle my_bundle -l site_bar

# In the end export config as usual.
drush -y config:export -l site_foo
drush -y config:export -l site_bar

To have a file field install sample yaml:

langcode: en
status: true
dependencies:
  config:
    - field.storage.paragraph.field_dlbox_files
    - paragraphs.paragraphs_type.dlbox
  module:
    - file
id: paragraph.dlbox.field_dlbox_files
field_name: field_dlbox_files
entity_type: paragraph
bundle: dlbox
label: Files
description: ''
required: false
translatable: true
default_value: {  }
default_value_callback: ''
settings:
  file_directory: paragraphs/dlboxfiles
  file_extensions: 'pdf doc docx'
  max_filesize: ''
  description_field: true
  handler: 'default:file'
  handler_settings: {  }
field_type: file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.