/   /   /  OroCRM Programming: system configuration with ui_only option

Note:

For more extensions and themes visit our store

OroCRM Programming: system configuration with ui_only option


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

  1.  
  2. oro_system_configuration:
  3.     groups:
  4.         yourvendor_yourbundle_manager_setting:
  5.             title: yourvendor_yourbundle.system_configuration.groups.settings.title
  6.             icon:  'icon-file'
  7.        yourvendor_yourbundle_manager_view:
  8.             title: yourvendor_yourbundle.system_configuration.groups.view.title</p>
  9.  
  10. <p>    fields:
  11.         yourvendor_yourbundle.allow:
  12.             ui_only: true
  13.             type: choice
  14.             priority: 70
  15.             options:
  16.                 label: yourvendor_yourbundle system_configuration.fields.allow.label
  17.                 required: false
  18.                 multiple: true
  19.                 choices:
  20.                     marketing: yourvendor_yourbundle system_configuration.fields.marketing
  21.                     activities: yourvendor_yourbundle.system_configuration.fields.activities
  22.     tree:
  23.         system_configuration:
  24.             platform:
  25.                 children:
  26.                     general_setup:
  27.                         children:
  28.                            yourvendor_yourbundle_setting:
  29.                                 priority: 400
  30.                                 children:
  31.                                    yourvendor_yourbundle_view:
  32.                                         priority: 100
  33.                                         children:
  34.                                             - ibnab_pmanger.allow
  35.  

All explain is inside the official documentation in top , but the more important part  for our tutorial is :
  1.  
  2.     fields:
  3.         yourvendor_yourbundle.allow:
  4.             ui_only: true
  5.             type: choice
  6.             priority: 70
  7.             options:
  8.                 label: yourvendor_yourbundle.system_configuration.fields.allow.label
  9.                 required: false
  10.                 multiple: true
  11.                 choices:
  12.                     marketing: yourvendor_yourbundle.system_configuration.fields.marketing
  13.                     activities: yourvendor_yourbundle.system_configuration.fields.activities
  14.  

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 :

  1.  
  2.                 if (!isset($this->variables[$varName]) && empty($varData['ui_only'])) {
  3.                     throw new InvalidConfigurationException(
  4.                         sprintf(
  5.                             'The system configuration variable "%s" is not defined.'
  6.                             . ' Please make sure that it is either added to bundle configuration settings'
  7.                             . ' or marked as "ui_only" in config.',
  8.                             $varName
  9.                         )
  10.                     );
  11.  

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:

  1.  
  2.         arguments:
  3.             - @oro_config.global
  4.  

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 :
  1.  
  2.  protected $configManager;
  3.     public function __construct(ConfigManager $configManager)
  4.     {
  5.         $this->configManager = $configManager;
  6.     }
  7.  

   Now you can use $this->configManager->get('yourvendor_yourbundle.allow') for getting vlaue

Comments

IBNAB is a company made of a group of professionals whose work is providing secure open source solutions. Our company strives for reaching magnificent results with each experience and provides professional open source solutions that cover every part of the business process.