/**
  * @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;
 }
 /**
  * {@inheritdoc}
  */
 protected function getBackendHeader()
 {
     $header = ['fieldName', 'is_serialized', 'type'];
     foreach ($this->fieldTypeProvider->getSupportedFieldTypes() as $fieldType) {
         $properties = $this->fieldTypeProvider->getFieldProperties($fieldType);
         foreach ($properties as $scope => $fields) {
             foreach ($fields as $code => $config) {
                 $field = sprintf('%s.%s', $scope, $code);
                 if (in_array($field, $this->excludedFields, true) || in_array($field, $header, true)) {
                     continue;
                 }
                 $header[] = $field;
             }
         }
     }
     return array_merge($header, ['enum.enum_options.0.label', 'enum.enum_options.0.is_default', 'enum.enum_options.1.label', 'enum.enum_options.1.is_default', 'enum.enum_options.2.label', 'enum.enum_options.2.is_default']);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function fillEntityData($key, $entity)
 {
     if (!$entity instanceof FieldConfigModel) {
         return;
     }
     /** @var FieldConfigModel $entity */
     $entity->setType($key)->setFieldName('field_' . $key);
     foreach ($this->fieldTypeProvider->getFieldProperties($key) as $scope => $properties) {
         $values = [];
         foreach ($properties as $code => $config) {
             if ($scope === 'enum' && $code === 'enum_options') {
                 $values = array_merge($values, $this->getEnumValues());
             } else {
                 $value = $this->getValueFromConfig($config);
                 if (is_bool($value)) {
                     $value = $value ? 'yes' : 'no';
                 }
                 $values[$code] = $value === null ? $code . '_value' : $value;
             }
         }
         $entity->fromArray($scope, $values, []);
     }
 }
Ejemplo n.º 4
0
 /**
  * @param FieldConfigModel $model
  * @param array $options
  */
 protected function updateModelConfig(FieldConfigModel $model, array $options)
 {
     $fieldProperties = $this->fieldTypeProvider->getFieldProperties($model->getType());
     foreach ($fieldProperties as $scope => $properties) {
         $values = [];
         foreach ($properties as $code => $config) {
             if (!isset($options[$scope][$code])) {
                 continue;
             }
             $value = $this->denormalizeFieldValue(isset($config['options']) ? $config['options'] : [], $options[$scope][$code], $model->getType());
             if ($value !== null) {
                 $values[$code] = $value;
             }
         }
         $model->fromArray($scope, $values, []);
     }
 }
Ejemplo n.º 5
0
 public function testGetFieldProperties()
 {
     $configType = PropertyConfigContainer::TYPE_FIELD;
     $fieldType = 'string';
     $scope = 'testScope';
     $code = 'test_code';
     $providerConfig = [$code => ['options' => [], 'form' => []]];
     $propertyConfig = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\PropertyConfigContainer')->disableOriginalConstructor()->getMock();
     $propertyConfig->expects($this->once())->method('hasForm')->with($configType, $fieldType)->willReturn($propertyConfig);
     $propertyConfig->expects($this->once())->method('getFormItems')->with($configType, $fieldType)->willReturn($providerConfig);
     $configProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
     $configProvider->expects($this->once())->method('getPropertyConfig')->willReturn($propertyConfig);
     $configProvider->expects($this->once())->method('getScope')->willReturn($scope);
     $this->configManager->expects($this->once())->method('getProviders')->willReturn([$configProvider]);
     $provider = new FieldTypeProvider($this->configManager, [], []);
     $this->assertEquals([$scope => $providerConfig], $provider->getFieldProperties($fieldType, $configType));
 }