menu
page

This project is not covered by Drupal’s security advisory policy.

The module provides a plugin for implementing custom translatable configuration forms. Also, it's a good way to centralize custom configurations and facilitate the development process.

Why do I need it?

I'm pretty sure that you've ever faced a situation when you need a piece of text to output somewhere or to provide a bunch of configurable elements for the site administrator. To achieve it, most likely you're going to be using one of these approaches:

1) Create a custom form, route, menu link, permissions, multilanguage support, set up services to store your configurations either in the database or in the configuration file.

2) Use content entity. But the problem is that it's not exportable. In this case, you have to define a custom configuration entity type which is not flexible enough.

In both cases, it's a pretty time-consuming process. But this module can solve some of these problems. All you need to do is to define a plugin in your custom module and describe the form fileds, validation and submit functions in a usual way, all the rest will be automatically solved. You can check out an example prepared in this module:

custom_configurations/src/Plugin/CustomConfigurations/ExampleConfigPlugin.php

To retrieve saved data you can use the CustomConfigurationsManager service:

/** @var \Drupal\custom_configurations\CustomConfigurationsManager $custom_configurations_manager */
$custom_configurations_manager = \Drupal::service('custom_configurations.manager');
// To get values saved to the configuration file. If $language is not set return the global value.
$custom_configurations_manager->getFileConfig($plugin_id, $var_name, $language);
// To get values saved to the data base. If $language is not set return the global value.
$custom_configurations_manager->getDbConfig($plugin_id, $var_name, $language);
// To get values for current language saved to the configuration file.
$custom_configurations_manager->getFileCurrentLanguageConfig($plugin_id, $var_name);
// To get values for current language saved to the data base.
$custom_configurations_manager->getDbCurrentLanguageConfig($plugin_id, $var_name);


Also available Twig functions:

{{ custom_configurations_get_file_config($plugin_id, $var_name, $global) }}
{{ custom_configurations_get_db_config($plugin_id, $var_name, $global) }}


FYI: To be able to see menu links, don't forget to flush drupal cache after defining a new plugin. If you didn't add any new allowed roles to the plugin configurations, then make sure the user you are using has the role administrator.

Supporting organizations: 

Project information

Releases