/** * Check for translatable values and preSet it on form * if have NO translation in translation catalogue return: * - field name (in case of creating new FieldConfigModel) * - empty string (in case of editing FieldConfigModel) * * @param FormEvent $event */ public function preSetData(FormEvent $event) { $configModel = $event->getForm()->getConfig()->getOption('config_model'); $data = $event->getData(); $dataChanges = false; foreach ($this->configManager->getProviders() as $provider) { $scope = $provider->getScope(); if (isset($data[$scope])) { $configId = $this->configManager->getConfigIdByModel($configModel, $scope); $translatable = $provider->getPropertyConfig()->getTranslatableValues($configId); foreach ($data[$scope] as $code => $value) { if (in_array($code, $translatable)) { if ($this->translator->hasTrans($value)) { $data[$scope][$code] = $this->translator->trans($value); } elseif (!$configModel->getId() && $configModel instanceof FieldConfigModel) { $data[$scope][$code] = $configModel->getFieldName(); } else { $data[$scope][$code] = ''; } $dataChanges = true; } } } } if ($dataChanges) { $event->setData($data); } }
/** * @param FormInterface $field * @param FormView $view */ protected function updateTooltip(FormInterface $field, FormView $view) { $parentOptions = $field->getParent()->getConfig()->getOptions(); $parentClassName = isset($parentOptions['data_class']) ? $parentOptions['data_class'] : null; if (!isset($view->vars['tooltip']) && $parentClassName && $this->entityConfigProvider->hasConfig($parentClassName, $field->getName())) { $tooltip = $this->entityConfigProvider->getConfig($parentClassName, $field->getName())->get('description'); //@deprecated 1.9.0:1.11.0 tooltips.*.yml will be removed. Use Resources/translations/messages.*.yml instead if ($this->translator->hasTrans($tooltip, self::DEFAULT_TRANSLATE_DOMAIN) || $this->translator->hasTrans($tooltip, self::TOOLTIPS_TRANSLATE_DOMAIN)) { $view->vars['tooltip'] = $tooltip; } } }