/**
  * @param string|null $type
  * @param array $data
  * @return FieldConfigModel
  */
 protected function createFieldConfigModel($type = null, array $data = [])
 {
     $entity = new FieldConfigModel();
     if ($type) {
         $entity->setType($type)->setFieldName('field_' . $type);
     }
     foreach ($data as $scope => $values) {
         $entity->fromArray($scope, $values, []);
     }
     return $entity;
 }
 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 $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, []);
     }
 }
 /**
  * @return array
  */
 public function processProvider()
 {
     $field = new FieldConfigModel('field_name', 'type1');
     $fieldWrongType = new FieldConfigModel('field_name', 'wrongType');
     $fieldSystem = new FieldConfigModel('field_name', 'type1');
     $fieldSystem->fromArray('extend', ['owner' => ExtendScope::OWNER_SYSTEM], []);
     return ['empty' => ['field' => new FieldConfigModel(), 'isExist' => false, 'expected' => null], 'filled' => ['field' => $field, 'isExist' => false, 'expected' => $field], 'wrong type' => ['field' => $fieldWrongType, 'isExist' => false, 'expected' => null], 'system' => ['field' => $fieldSystem, 'isExist' => true, 'expected' => null]];
 }
 /**
  * @param ConfigManager    $configManager
  * @param FieldConfigModel $fieldModel
  * @param array            $options
  */
 protected function updateFieldConfigs(ConfigManager $configManager, FieldConfigModel $fieldModel, $options)
 {
     $className = $fieldModel->getEntity()->getClassName();
     $fieldName = $fieldModel->getFieldName();
     foreach ($options as $scope => $scopeValues) {
         $configProvider = $configManager->getProvider($scope);
         $config = $configProvider->getConfig($className, $fieldName);
         $hasChanges = false;
         foreach ($scopeValues as $code => $val) {
             if (!$config->is($code, $val)) {
                 $config->set($code, $val);
                 $hasChanges = true;
             }
         }
         if ($hasChanges) {
             $configProvider->persist($config);
             $indexedValues = $configProvider->getPropertyConfig()->getIndexedValues($config->getId());
             $fieldModel->fromArray($config->getId()->getScope(), $config->all(), $indexedValues);
         }
     }
 }