Forums › Forums › OroPlatform › OroPlatform – How do I? Questions › How to customize default settings?
This topic contains 1 reply, has 2 voices, and was last updated by igalayev 6 years, 9 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- June 30, 2017 at 2:22 am #36488
Hello.
For some time, I’m trying to customize default settings for Oro Platform application.
For example, I’m trying to set initial values into oro_config_value table (eg. sidebar_left_active, sidebar_right_active, enabled_localizations).Is it possible to do it?
Thanks!
- CreatorTopic
- AuthorReplies
- July 21, 2017 at 6:47 am #36489
Hello, you can do it with help of data migrations.
More on working with configuration you can read here https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/ConfigBundle/README.md
So to change sidebar values you have to create this migration and load it:
PHP1234567891011121314151617181920212223242526namespace Oro\Bundle\SidebarBundle\Migrations\Data\ORM;use Doctrine\Common\Persistence\ObjectManager;use Doctrine\Common\DataFixtures\AbstractFixture;use Oro\Bundle\ConfigBundle\Config\ConfigManager;use Symfony\Component\DependencyInjection\ContainerAwareInterface;use Symfony\Component\DependencyInjection\ContainerAwareTrait;class UpdateSidebarSettings extends AbstractFixture implements ContainerAwareInterface{use ContainerAwareTrait;/*** Assign exists sidebar widgets to the default organization** @param \Doctrine\Common\Persistence\ObjectManager $manager*/public function load(ObjectManager $manager){/** @var ConfigManager $configManager */$configManager = $this->container->get('oro_config.global');$configManager->set('oro_sidebar.sidebar_left_active', 1);$configManager->set('oro_sidebar.sidebar_right_active', 0);$configManager->flush();}}Similar approach works with enabled localizations, create data migration and pass an array of enabled localizations’ ids. Here’s a sample code of adding English (Canada) localization to enabled localizations.
PHP123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354<?phpnamespace Oro\Bundle\LocaleBundle\Migrations\Data\ORM;use Doctrine\Common\DataFixtures\AbstractFixture;use Doctrine\Common\DataFixtures\DependentFixtureInterface;use Doctrine\Common\Persistence\ObjectManager;use Symfony\Component\DependencyInjection\ContainerAwareInterface;use Symfony\Component\DependencyInjection\ContainerAwareTrait;use Symfony\Component\Intl\Intl;use Oro\Bundle\ConfigBundle\Config\ConfigManager;use Oro\Bundle\LocaleBundle\Entity\Localization;use Oro\Bundle\LocaleBundle\DependencyInjection\Configuration;use Oro\Bundle\TranslationBundle\Entity\Language;use Oro\Bundle\TranslationBundle\Migrations\Data\ORM\LoadLanguageData;use Oro\Bundle\TranslationBundle\Translation\Translator;class LoadLocalizations extends AbstractFixture implements ContainerAwareInterface, DependentFixtureInterface{use ContainerAwareTrait;/*** {@inheritdoc}*/public function load(ObjectManager $manager){$configManager = $this->container->get('oro_config.global');$enabledLocalizationIds = $configManager->get('oro_locale.enabled_localizations');$repository = $this->container->get('doctrine')->getManagerForClass(Localization::class)->getRepository(Localization::class);$localization = $repository->findOneBy(['name' => 'English (Canada)']);$configManager->set('oro_locale.enabled_localizations',array_merge($enabledLocalizationIds, [$localization->getId()]));$configManager->flush();}/*** {@inheritdoc}*/public function getDependencies(){return [LoadLocalizationData::class];}} - AuthorReplies
The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.