Exemplo n.º 1
0
 public function testConfig()
 {
     $this->assertEquals($this->configManager, $this->configProvider->getConfigManager());
     $this->assertEquals(true, $this->configProvider->hasConfig(DemoEntity::ENTITY_NAME));
     $this->assertEquals($this->entityConfig, $this->configProvider->getConfig(DemoEntity::ENTITY_NAME));
     $this->assertEquals('testScope', $this->configProvider->getScope());
     $entityConfigId = new EntityConfigId('testScope', DemoEntity::ENTITY_NAME);
     $fieldConfigId = new FieldConfigId('testScope', DemoEntity::ENTITY_NAME, 'testField', 'string');
     $this->assertEquals($entityConfigId, $this->configProvider->getId(DemoEntity::ENTITY_NAME));
     $this->assertEquals($fieldConfigId, $this->configProvider->getId(DemoEntity::ENTITY_NAME, 'testField', 'string'));
     $entityConfigIdWithOtherScope = new EntityConfigId('otherScope', DemoEntity::ENTITY_NAME);
     $this->assertEquals($this->entityConfig, $this->configProvider->getConfigById($entityConfigIdWithOtherScope));
 }
Exemplo n.º 2
0
 /**
  * @param ConfigProvider $provider
  * @param ConfigInterface $config
  * @param array $data
  * @param string $state
  * @return array
  */
 protected function processData(ConfigProvider $provider, ConfigInterface $config, array $data, $state)
 {
     if ($provider->getScope() === 'enum' && $config->get('enum_code')) {
         return [];
     }
     $translatable = $provider->getPropertyConfig()->getTranslatableValues($config->getId());
     $translations = [];
     foreach ($data as $code => $value) {
         if (in_array($code, $translatable, true)) {
             // check if a label text was changed
             $labelKey = $config->get($code);
             if ($state === ExtendScope::STATE_NEW || !$this->translationHelper->isTranslationEqual($labelKey, $value)) {
                 $translations[$labelKey] = $value;
             }
             // replace label text with label name in $value variable
             $value = $labelKey;
         }
         $config->set($code, $value);
     }
     $this->configManager->persist($config);
     return $translations;
 }
Exemplo n.º 3
0
 /**
  * @param ConfigProvider $provider
  */
 public function addProvider(ConfigProvider $provider)
 {
     $this->providers[$provider->getScope()] = $provider;
 }
Exemplo n.º 4
0
 /**
  * Extracts field default values from an annotation and config file
  *
  * @param ConfigProvider     $provider
  * @param string             $className
  * @param string             $fieldName
  * @param string             $fieldType
  * @param FieldMetadata|null $metadata
  * @return array
  */
 protected function getFieldDefaultValues(ConfigProvider $provider, $className, $fieldName, $fieldType, $metadata = null)
 {
     $defaultValues = [];
     $scope = $provider->getScope();
     // try to get default values from an annotation
     if ($metadata && isset($metadata->defaultValues[$scope])) {
         $defaultValues = $metadata->defaultValues[$scope];
     }
     // combine them with default values from a config file
     $defaultValues = array_merge($provider->getPropertyConfig()->getDefaultValues(PropertyConfigContainer::TYPE_FIELD, $fieldType), $defaultValues);
     // process translatable values
     $translatablePropertyNames = $provider->getPropertyConfig()->getTranslatableValues(PropertyConfigContainer::TYPE_FIELD);
     foreach ($translatablePropertyNames as $propertyName) {
         if (empty($defaultValues[$propertyName])) {
             $defaultValues[$propertyName] = ConfigHelper::getTranslationKey($scope, $propertyName, $className, $fieldName);
         }
     }
     return $defaultValues;
 }