Custom Configuration

Categories

Component ID

2883010

Component name

Custom Configuration

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

368

Component created

Component changed

Component body

Custom configuration management for a single site, Multi site & Multilingual.

This is a new module in Drupal8. This module is more helpful where you want to save multiple configurations like Facebook, Twitter, Google Auth key and etc.

This module also work with multi domain, multi website and multilingual.

This module provides the following functionality:

1. Create a un-limited number of configuration.
2. Easy to use and understand.
3. Access saved configuration by machine name.
4. Set configuration as Active or Inactive, in case of inactive if you try to access configuration it will return null.
5. Provides service to access configuration value by machine name.
6. If you are trying to access any non-exists machine name value, it will return null.

How to access configuration value by Machine name, Language code and Domain key:

Syntax:
$value = Drupal::service('custom.configuration')->getValue(machine_name,language_code,domain_key);
Parameters:
machine_name : required machine name.
language_code : Language code of machine name that you want to get. If you will not pass
language_code it will get value of current active language.
domain_key : Domain key of machine name that you want to get. If you will not pass
domain_key it will get value of current active domain.

Example :
Suppose there is a machine name mobile and want to get value.

$value = Drupal::service('custom.configuration')->getValue('mobile');
Sample output:
11111111111

How to access configuration value & optional value by Machine name, Language code and Domain key:

Syntax:
$value = Drupal::service('custom.configuration')->getValues(machine_name,language_code,domain_key);
Parameters:
machine_name : required machine name.
language_code : Language code of machine name that you want to get. If you will not pass
language_code it will get value of current active language.
domain_key : Domain key of machine name that you want to get. If you will not pass
domain_key it will get value of current active domain.

Example :
Suppose there is a machine name mobile and want to get value & optional values.

$value = Drupal::service('custom.configuration')->getValues('mobile');

Sample output :
stdClass Object
(
[machine_name] => mobile
[name] => Mobile Number
[value] => 11111111111
[langcode] => Array
(
[0] => en
)

[domain_key] => Array
(
[0] => default
)

[optional] => Array
(
[value_1] => Sales Team
[value_2] => Office Phone
[value_3] => Call at 9:00 AM - 6:00 PM
[value_4] => Saturday & Sunday Closed
)

)

How to access Configuration module:

Home -> Administration -> Custom Configuration