本文整理汇总了PHP中Oro\Bundle\EntityConfigBundle\Config\ConfigManager::getConfigIdByModel方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigManager::getConfigIdByModel方法的具体用法?PHP ConfigManager::getConfigIdByModel怎么用?PHP ConfigManager::getConfigIdByModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityConfigBundle\Config\ConfigManager
的用法示例。
在下文中一共展示了ConfigManager::getConfigIdByModel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postSubmit
/**
* @param FormEvent $event
*/
public function postSubmit(FormEvent $event)
{
$form = $event->getForm();
$configModel = $form->getConfig()->getOption('config_model');
$data = $event->getData();
$labelsToBeUpdated = [];
foreach ($this->configManager->getProviders() as $provider) {
$scope = $provider->getScope();
if (isset($data[$scope])) {
$configId = $this->configManager->getConfigIdByModel($configModel, $scope);
$config = $provider->getConfigById($configId);
$translatable = $provider->getPropertyConfig()->getTranslatableValues($configId);
foreach ($data[$scope] as $code => $value) {
if (in_array($code, $translatable, true)) {
// check if a label text was changed
$labelKey = $config->get($code);
if (!$configModel->getId()) {
$labelsToBeUpdated[$labelKey] = $value;
} elseif ($value != $this->translator->trans($labelKey)) {
$labelsToBeUpdated[$labelKey] = $value;
}
// replace label text with label name in $value variable
$value = $config->get($code);
}
$config->set($code, $value);
}
$this->configManager->persist($config);
}
}
if ($form->isValid()) {
// update changed labels if any
if (!empty($labelsToBeUpdated)) {
/** @var EntityManager $translationEm */
$translationEm = $this->doctrine->getManagerForClass(Translation::ENTITY_NAME);
/** @var TranslationRepository $translationRepo */
$translationRepo = $translationEm->getRepository(Translation::ENTITY_NAME);
$values = [];
$locale = $this->translator->getLocale();
foreach ($labelsToBeUpdated as $labelKey => $labelText) {
// save into translation table
$values[] = $translationRepo->saveValue($labelKey, $labelText, $locale, TranslationRepository::DEFAULT_DOMAIN, Translation::SCOPE_UI);
}
// mark translation cache dirty
$this->dbTranslationMetadataCache->updateTimestamp($locale);
$translationEm->flush($values);
}
$this->configManager->flush();
}
}