how to define system configuration?

177 views Asked by At

I use oro platform v4.1 I try to defind configuration value to system according to https://doc.oroinc.com/4.1/backend/system-configuration/

so

class Configuration implements ConfigurationInterface
{

    /**
     * {@inheritDoc}
     */
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('web_sys_visit');

        // Here you should define the parameters that are allowed to
        // configure your bundle. See the documentation linked above for
        // more information on that topic.

        SettingsBuilder::append($rootNode, [
            'nogps' => [
                'value' => true,
                'type' => 'boolean',
            ]
        ]);


        return $treeBuilder;
    }
}

and system_configuration.yml

system_configuration:
    groups:
        websys_visit_settings:
            title: visit setting
    fields:
        web_sys_visit.nogps:
            data_type: boolean
            type: Oro\Bundle\ConfigBundle\Form\Type\ConfigCheckbox
            priority: 10
            options:
                label: No GPS
    tree:
        system_configuration:
            platform:
                children:
                    general_setup:
                        children:
                            application_settings:
                                children:
                                    websys_visit_settings:
                                        children:
                                            - web_sys_visit.nogps
class WebSysVisitExtension extends Extension
{
    const ALIAS = 'web_sys_visit';

    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('services.yml');
        $loader->load('form.yml');
    }

    /**
     * {@inheritDoc}
     */
    public function getAlias()
    {
        return self::ALIAS;
    }
}

when I try to clear the cache I have the below error

The system configuration variable "web_sys_visit.nogps" is not defined. Please make sure that it is either added to bundle configuration
settings or marked as "ui_only" in config.

so I add

ui_only: true

to the configuration and clear cache and then run oro:entity-config:update

I see gps configuration in system configuration but when I set value true, It was not saved

I check oro_confige_value table in db ,there is no config as nogps ( section =web_sys_visit) should I run any command? could you help me? Thanks

1

There are 1 answers

0
Andrey Yatsenko On

ui_only means that the value is not saved automatically by the framework and you have to handle it manually.

It seems the Configuration class is not loaded. Make sure namespaces and file paths are correct and your bundle class name is WebSysVisitBundle, otherwise the extension name is incorrect.