The system configuration is important tool for creating global value used to customize or setup tasks
, in OroCRM you can find the technique of how creating in official documentation :
http://www.orocrm.com/documentation/index/current/book/configuration
here ibnab giving you other way to create and get value from system configuration .
By ui_only: true and Configuration Provider , Yes but what is this ?
`ui_only` - indicates whether a field is used only on UI and do not related to any variable (optional, defaults to false) = if you have a field doesn't need variable values or default value you can use ui_only
other property of field :
// 'data_type' be specified for all fields except 'ui_only' ones
Field declaration have required property `type`.
`type` - refers to form type of which field should be created
`tooltip` - show additional info about field
`acl_resource` - determines acl resource to check permissions to change config field value(optional)
`priority` - sort order for displaying(optional)
Create inside YourVendor/YourBundle/Resource/config/system_configuration.yml
oro_system_configuration: groups: yourvendor_yourbundle_manager_setting: title: yourvendor_yourbundle.system_configuration.groups.settings.title icon: 'icon-file' yourvendor_yourbundle_manager_view: title: yourvendor_yourbundle.system_configuration.groups.view.title</p> <p> fields: yourvendor_yourbundle.allow: ui_only: true type: choice priority: 70 options: label: yourvendor_yourbundle system_configuration.fields.allow.label required: false multiple: true choices: marketing: yourvendor_yourbundle system_configuration.fields.marketing activities: yourvendor_yourbundle.system_configuration.fields.activities tree: system_configuration: platform: children: general_setup: children: yourvendor_yourbundle_setting: priority: 400 children: yourvendor_yourbundle_view: priority: 100 children: - ibnab_pmanger.allow
All explain is inside the official documentation in top , but the more important part for our tutorial is :
fields: yourvendor_yourbundle.allow: ui_only: true type: choice priority: 70 options: label: yourvendor_yourbundle.system_configuration.fields.allow.label required: false multiple: true choices: marketing: yourvendor_yourbundle.system_configuration.fields.marketing activities: yourvendor_yourbundle.system_configuration.fields.activities
See the ui_only: true, and options with property choices contain two static value and is multiple choice , we finished , you don't need to redeclare inside DependencyInjection/Configuration.php because oro in vendor/oro/platform/src/Oro/Bundle/ConfigBundle/DependencyInjection/SystemConfiguration/ProcessorDecorator.php
test on two level :
throw new InvalidConfigurationException( 'The system configuration variable "%s" is not defined.' . ' Please make sure that it is either added to bundle configuration settings' . ' or marked as "ui_only" in config.', $varName ) );
if is variable and declared inside Configuration.php continue ,if not see if have ui_only if not throw InvalidConfigurationException .
Ok now what about Configuration Provider for example I want use my the value of this field outside controller , here I need create Configuration Provider and inject to my target class .
1 – Create my provider inside our services.yml I can pass as argument to any service @oro_config.global:
arguments: - @oro_config.global
is object of type Oro\Bundle\ConfigBundle\Config\ConfigManager give you the ability to use the function get('pathtoyourfield');
for example the construct of our class is :
protected $configManager; public function __construct(ConfigManager $configManager) { $this->configManager = $configManager; }
Now you can use $this->configManager->get('yourvendor_yourbundle.allow') for getting vlaue
Comments