3

While creating custom configuration forms, I'm getting an access denied. But on the /translation page of the form only. Configuration form itself can be reached, filled and updated without problems.

Configuration does show up on the admin/config/regional/config-translation page but can't be translated for some reason.

Any idea's?

Overview of files:

schema.yml

faq.settings:
  type: mapping
  label: 'FAQ settings'
  mapping:
    faq_title:
      type: text
      label: 'Title'
    faq_text:
      type: text
      label: 'Text'
    faq_cta_label:
      type: text
      label: 'CTA label'
    faq_cta:
      type: text
      label: 'CTA'
...

routing.yml

aform.faq:
  path: '/admin/config/aform/faq'
  defaults:
    _form: '\Drupal\aform\Form\faqForm'
    _title: 'FAQ block'
  requirements:
    _permission: 'administer site configuration'
...

config_translation.yml

aform.faq:
  title: 'aform FAQ'
  base_route_name: aform.faq
  names:
    - faq.settings
...

2 Answers 2

1

For anyone stumbling towards a similar problem: it seems you have to set-up not only schema, routing and config_translations yml files but you also have to define each configuration in installation yml files so your config is picked up by Drupal.

So I had to include a faq.settings.yml file in /install of my custom module directory, like:

faq_title: ''
faq_text: ''
faq_cta_label: ''
faq_cta: ''
langcode: en

And boom you got yourself a translatable configuration form.

6
  • As it turns out you don't need the install yml files. The translation is only possible if the config is set in the default language...
    – hofmann
    Mar 31, 2017 at 12:13
  • I stumbled across the same issue as @hofmann , getting access denied for just the translation. The config form appears and I can save that. My default language is set as Arabic and I added 'ar' in settings.yml file. I posted a question on this as I cant add all my code here. It would be great if you can suggest any cause for this.
    – wilNev
    Jun 8, 2017 at 6:56
  • It seems I don't have enough credits to answer your question on your link so I'm going to answer it here: the point is you first have to set the config in the default language. After saving I was able to translate it to other languages without problems. Sometimes caching may prevent displaying the translate link if you are using local tabs. So when you have a config form for slogan for example you first have to set the default language slogan (ex: in English) after that you will be able to translate it to French, Duch,...
    – hofmann
    Jun 8, 2017 at 9:41
  • Thanks for the suggestion. In my case the default lang configured for my site is Arabic. Even after saving the config form in Arabic the translation tab is not displayed. Is there anything more I should add to the yml files?
    – wilNev
    Jun 8, 2017 at 9:47
  • In order for the translation tab to be displayed you will need to properly set-up your module.links.task.yml, module.links.menu.yml, module.config_translation.yml and important also your config/schema : module.shema.yml. If your config is set up properly you will also find it here: admin/config/regional/config-translation
    – hofmann
    Jun 8, 2017 at 11:55
0

It can take quite a while until you get all the naming correct. For people struggling with this, we've published a module with a working example here: https://github.com/VITObelgium/drupal-boilerplate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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