0

I have the following file.

modules/custom/test_module/config/install/test_module.settings.yml

test_module.settings:
    message: 'Hello'
    langcode: 'en'

But I am not able to get the following value.

$config = \Drupal::config('test_module.settings');
print $config->get('message');    

I have referred this link.

UPDATE:

Removing test_module.settings: line solved the issue.

1
test_module.settings:
    message: 'Hello'
    langcode: 'en'

Is that really content of your file? It should only contain:

message: 'Hello'
langcode: 'en'

Also, Configuration on config/install is only imported when a module is installed. If it is an existing module, you need to re-install it or write an update function to initialize the configuration.

You can always use something like print_r($config->get()) to see everything in your config file.

  • Thank you. Is there any other way to use these configuration? Means other than config/install so that there is no necessary to re-install the module. – Dushyant Joshi Jul 25 '17 at 10:20
  • 1
    You can import the configuration manually using the single config import UI or a configuration sync but no, there is no process to do anything like that automatically. – Berdir Jul 25 '17 at 12:35

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.