Пример #1
0
 /**
  * @param FieldConfigModel $configModel
  * @return array
  */
 protected function writeItem(FieldConfigModel $configModel)
 {
     $className = $configModel->getEntity()->getClassName();
     $fieldName = $configModel->getFieldName();
     $state = ExtendScope::STATE_UPDATE;
     if (!$this->configManager->hasConfig($className, $fieldName)) {
         $this->configManager->createConfigFieldModel($className, $fieldName, $configModel->getType());
         $state = ExtendScope::STATE_NEW;
     }
     $translations = [];
     foreach ($this->configManager->getProviders() as $provider) {
         $scope = $provider->getScope();
         $data = $configModel->toArray($scope);
         if (!$data) {
             continue;
         }
         $translations = array_merge($translations, $this->processData($provider, $provider->getConfig($className, $fieldName), $data, $state));
     }
     $this->setExtendData($className, $fieldName, $state);
     $this->updateEntityState($className);
     if ($state === ExtendScope::STATE_UPDATE && in_array($configModel->getType(), ['enum', 'multiEnum'], true)) {
         $this->setEnumData($configModel->toArray('enum'), $className, $fieldName);
     }
     return $translations;
 }
Пример #2
0
 public function testToFromArray()
 {
     $this->configValue->setCode('doctrine')->setScope('datagrid')->setValue('a:2:{s:4:"code";s:8:"test_001";s:4:"type";s:6:"string";}');
     $values = array('is_searchable' => true, 'is_sortable' => false, 'doctrine' => $this->configValue);
     $serializable = array('doctrine' => true);
     $this->configField->addValue(new ConfigModelValue('is_searchable', 'datagrid', false));
     $this->configField->fromArray('datagrid', $values, $serializable);
     $this->assertEquals(array('is_searchable' => 1, 'is_sortable' => 0, 'doctrine' => $this->configValue), $this->configField->toArray('datagrid'));
     $this->configEntity->addValue(new ConfigModelValue('is_searchable', 'datagrid', false));
     $this->configEntity->fromArray('datagrid', $values, $serializable);
     $this->assertEquals(array('is_searchable' => 1, 'is_sortable' => 0, 'doctrine' => $this->configValue), $this->configEntity->toArray('datagrid'));
 }
 /**
  * @param FieldConfigModel $entity
  * @return array
  */
 protected function validateEntityFields(FieldConfigModel $entity)
 {
     $errors = [];
     $fieldProperties = $this->fieldTypeProvider->getFieldProperties($entity->getType());
     foreach ($fieldProperties as $scope => $properties) {
         $scopeData = $entity->toArray($scope);
         foreach ($properties as $code => $config) {
             if (!isset($scopeData[$code])) {
                 continue;
             }
             if ($scope === 'enum') {
                 foreach ($scopeData[$code] as $key => $enumFields) {
                     $result = $this->strategyHelper->validateEntity(EnumValue::createFromArray($enumFields));
                     if ($result) {
                         $errors[] = sprintf('%s.%s.%s: %s', $scope, $code, $key, implode(' ', $result));
                     }
                 }
             } elseif (isset($config['constraints'])) {
                 $result = $this->strategyHelper->validateEntity($scopeData[$code], $this->constraintFactory->parse($config['constraints']));
                 if ($result) {
                     $errors[] = sprintf('%s.%s: %s', $scope, $code, implode(' ', $result));
                 }
             }
         }
     }
     return $errors;
 }