0

I have managed_file in my module configuration form and one text field, so I want to set default values for these fields on module install.

At the moment I have this in config/install/my_module.settings.yml:

title: 'Hello!'
langcode: en

and this in config/schema/my_module.schema.yml:

my_module.settings:
  type: config_object
  mapping:
    title:
      type: string
      label: 'Title'
    langcode:
      type: string
      label: 'Language code'

Now, how I can upload some PNG image file on module install and how to define it in my_module.schema.yml and my_module.settings.yml in order to set it as default?


Update

If I want to leave this field empty is this right way to define it in config?

config/install/my_module.settings.yml

title: 'Hello!'
image: NULL
langcode: en

config/schema/my_module.schema.yml

my_module.settings:
  type: config_object
  mapping:
    title:
      type: string
      label: 'Title'
    image:
      type: integer
      label: 'Image'
    langcode:
      type: string
      label: 'Language code'

This doesn't work, the problem is to define managed_file in schema file, how to do that?

  • You need a form to upload a file, so perhaps set a message in hook_install inviting users to visit an admin form where they can do so. Or, include the file with your module, then use the API to save it as a managed file without an upload. It probably can't go in the settings.yml as you won't know the file ID ahead of time – Clive Aug 17 '17 at 13:45
  • hey @Clive thanks for the answer...I updated my question, can you take a look and confirm me that I'm on the right way? – mixerowsky Aug 17 '17 at 14:10

Your Answer

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

Browse other questions tagged or ask your own question.