Important
You are browsing documentation for version 5.1 of OroCommerce, supported until March 2027. Read the documentation for the latest LTS version to get up-to-date information.
See our Release Process documentation for more information on the currently supported and upcoming releases.
Access Entities Configuration
Now that you know how to define additional configuration options and use them in your own entities, you will usually want to access the configured values. The main entry point is the provider service for the particular scope, which you retrieve from the service container.
For example, to work with your newly created auditable option, use the
oro_entity_config.provider.acme_demo service (the auditable option was defined in the
acme_demo scope):
/** @var Symfony\Component\DependencyInjection\ContainerInterface $container */
$container = ...;
$acmeDemoProvider = $container->get('oro_entity_config.provider.acme_demo');
Then fetch the configuration in this scope for a particular entity or entity field
using the Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider::getConfig method. The
configuration for such a configurable object (an entity or a field) is an instance
of the Oro\Bundle\EntityConfigBundle\Config\ConfigInterface:
get()Returns the actually configured value for an option.
set()Changes the value of an option to a new value.
remove()Removes the particular option.
has()Checks whether or not an option with the given name exists.
is()Checks if the value of an option equals the given value.
in()Checks if the value of an option is one of the given values.
all()Returns all parameters for the configurable object.
setValues()Replaces values for the given options with some given values.
Modifying configuration values in the provider is not enough. You must also force your changes
afterwards by calling the Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider::flush
method:
// ...
$acmeDemoProvider = $container->get('oro_entity_config.provider.acme_demo');
$acmeConfig = $acmeDemoProvider->getConfig('Acme\Bundle\DemoBundle\Entity\Document');
$acmeConfig->set('comment', 'Updated comment');
$acmeDemoProvider->getConfigManager()->flush();
Tip
Use the oro:entity-config:debug command to display entity configuration and access or modify configuration values from the command line.