/**
  * Process field
  *
  * @param array           $mapConfig
  * @param ConfigInterface $searchConfig
  * @param FieldConfigId   $fieldId
  * @param string          $className
  */
 protected function processFields(&$mapConfig, ConfigInterface $searchConfig, FieldConfigId $fieldId, $className)
 {
     $extendConfigProvider = $this->configManager->getProvider('extend');
     $fieldName = $fieldId->getFieldName();
     if ($searchConfig->is('searchable')) {
         $fieldType = $this->transformCustomType($fieldId->getFieldType());
         if (in_array($fieldType, [Indexer::RELATION_ONE_TO_ONE, Indexer::RELATION_MANY_TO_ONE])) {
             $config = $extendConfigProvider->getConfig($className, $fieldName);
             $targetEntity = $config->get('target_entity');
             $targetField = $config->get('target_field');
             $targetType = $this->transformCustomType($this->configManager->getId('extend', $targetEntity, $targetField)->getFieldType());
             $field = ['name' => $fieldName, 'relation_type' => $fieldType, 'relation_fields' => [['name' => $targetField, 'target_type' => $targetType, 'target_fields' => [strtolower($fieldName . '_' . $targetField)]]]];
         } elseif (in_array($fieldType, [Indexer::RELATION_MANY_TO_MANY, Indexer::RELATION_ONE_TO_MANY])) {
             $config = $extendConfigProvider->getConfig($className, $fieldName);
             $targetEntity = $config->get('target_entity');
             $targetFields = array_unique(array_merge($config->get('target_grid'), $config->get('target_title'), $config->get('target_detailed')));
             $fields = [];
             foreach ($targetFields as $targetField) {
                 $targetType = $this->transformCustomType($this->configManager->getId('extend', $targetEntity, $targetField)->getFieldType());
                 $fields[] = ['name' => $targetField, 'target_type' => $targetType, 'target_fields' => [strtolower($fieldName . '_' . $targetField)]];
             }
             $field = ['name' => $fieldName, 'relation_type' => $fieldType, 'relation_fields' => $fields];
         } else {
             $field = ['name' => $fieldName, 'target_type' => $fieldType, 'target_fields' => [strtolower($fieldName)]];
         }
         $mapConfig[$className][self::FIELDS_PATH][] = $field;
     }
 }
Ejemplo n.º 2
0
 /**
  * @param FieldConfigId $selfFieldId
  * @param string        $targetEntity
  * @return string
  */
 public static function generateManyToManyJoinTableName(FieldConfigId $selfFieldId, $targetEntity)
 {
     $selfClassArray = explode('\\', $selfFieldId->getClassName());
     $selfClassName = array_pop($selfClassArray);
     $targetClassArray = explode('\\', $targetEntity);
     $targetClassName = array_pop($targetClassArray);
     return strtolower('oro_extend_' . $selfClassName . '_' . $targetClassName . '_' . $selfFieldId->getFieldName());
 }
Ejemplo n.º 3
0
 public function testSetState()
 {
     $fieldId = FieldConfigId::__set_state(['className' => 'Test\\Class', 'scope' => 'testScope', 'fieldName' => 'testField', 'fieldType' => 'string']);
     $this->assertEquals('Test\\Class', $fieldId->getClassName());
     $this->assertEquals('testScope', $fieldId->getScope());
     $this->assertEquals('testField', $fieldId->getFieldName());
     $this->assertEquals('string', $fieldId->getFieldType());
 }
Ejemplo n.º 4
0
 public function testGetConfig()
 {
     $this->assertEquals('Test\\Class', $this->fieldId->getClassName());
     $this->assertEquals('testScope', $this->fieldId->getScope());
     $this->assertEquals('testField', $this->fieldId->getFieldName());
     $this->assertEquals('string', $this->fieldId->getFieldType());
     $this->assertEquals('field_testScope_Test-Class_testField', $this->fieldId->toString());
     $this->fieldId->setFieldType('integer');
     $this->assertEquals('integer', $this->fieldId->getFieldType());
 }
Ejemplo n.º 5
0
 /**
  * Guess formatters for given fieldConfigId
  * Returns array with data:
  *   - formatters: array with supported formatters for given field
  *   - default_formatter: default formatter for given field
  *
  * @param FieldConfigId $configId
  *
  * @return array|null
  */
 public function guessFormatters(FieldConfigId $configId)
 {
     $fieldType = $configId->getFieldType();
     $formatters = [];
     $defaultFormatter = null;
     $found = false;
     foreach ($this->formatters as $formatterName => $formatter) {
         $isSupport = in_array($fieldType, $formatter->getSupportedTypes());
         if ($isSupport) {
             $found = true;
             $formatters[] = $formatterName;
             if ($formatter->isDefaultFormatter()) {
                 $defaultFormatter = $formatterName;
             }
         }
     }
     if ($found) {
         return ['formatters' => $formatters, 'default_formatter' => $defaultFormatter];
     }
     return null;
 }
Ejemplo n.º 6
0
 public function testNewEnumNameValidators()
 {
     $configId = new FieldConfigId('enum', 'Test\\Entity', 'testField', 'enum');
     $this->typeHelper->expects($this->any())->method('hasEnumCode')->with($configId->getClassName(), $configId->getFieldName())->will($this->returnValue(false));
     $resolver = $this->getOptionsResolver();
     $this->type->setDefaultOptions($resolver);
     $resolvedOptions = $resolver->resolve(['config_id' => $configId]);
     $this->assertCount(5, $resolvedOptions['constraints']);
     $this->assertInstanceOf('Symfony\\Component\\Validator\\Constraints\\NotBlank', $resolvedOptions['constraints'][0]);
     $this->assertInstanceOf('Symfony\\Component\\Validator\\Constraints\\Length', $resolvedOptions['constraints'][1]);
     $this->assertEquals($this->nameGenerator->getMaxEnumCodeSize(), $resolvedOptions['constraints'][1]->max);
     $this->assertInstanceOf('Symfony\\Component\\Validator\\Constraints\\Regex', $resolvedOptions['constraints'][2]);
     $this->assertEquals('/^[\\w- ]*$/', $resolvedOptions['constraints'][2]->pattern);
     $this->assertEquals(EnumNameType::INVALID_NAME_MESSAGE, $resolvedOptions['constraints'][2]->message);
     $this->assertInstanceOf('Symfony\\Component\\Validator\\Constraints\\Callback', $resolvedOptions['constraints'][3]);
     $context = $this->getMockBuilder('Symfony\\Component\\Validator\\ExecutionContext')->disableOriginalConstructor()->getMock();
     $context->expects($this->once())->method('addViolation')->with(EnumNameType::INVALID_NAME_MESSAGE);
     call_user_func($resolvedOptions['constraints'][3]->methods[0], '!@#$', $context);
     $this->assertInstanceOf('Oro\\Bundle\\EntityExtendBundle\\Validator\\Constraints\\UniqueEnumName', $resolvedOptions['constraints'][4]);
     $this->assertEquals($configId->getClassName(), $resolvedOptions['constraints'][4]->entityClassName);
     $this->assertEquals($configId->getFieldName(), $resolvedOptions['constraints'][4]->fieldName);
 }
 /**
  * @param ConfigInterface $fieldConfig
  * @param string $relationKey
  */
 protected function createTargetRelation(ConfigInterface $fieldConfig, $relationKey)
 {
     /** @var FieldConfigId $fieldConfigId */
     $fieldConfigId = $fieldConfig->getId();
     $selfFieldId = new FieldConfigId('extend', $fieldConfigId->getClassName(), $fieldConfigId->getFieldName(), $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType()));
     $targetEntityClass = $fieldConfig->get('target_entity');
     $selfConfig = $this->extendConfigProvider->getConfig($selfFieldId->getClassName());
     $selfRelations = $selfConfig->get('relation');
     $selfRelationConfig =& $selfRelations[$relationKey];
     $selfRelationConfig['field_id'] = $selfFieldId;
     $targetConfig = $this->extendConfigProvider->getConfig($targetEntityClass);
     $targetRelations = $targetConfig->get('relation');
     $targetRelationConfig =& $targetRelations[$relationKey];
     $targetRelationConfig['target_field_id'] = $selfFieldId;
     $selfConfig->set('relation', $selfRelations);
     $targetConfig->set('relation', $targetRelations);
     $this->extendConfigProvider->persist($targetConfig);
 }
Ejemplo n.º 8
0
 /**
  * @param FieldConfigId $fieldConfigId
  *
  * @return string
  */
 protected function getRelationKey(FieldConfigId $fieldConfigId)
 {
     return ExtendHelper::buildRelationKey($fieldConfigId->getClassName(), $fieldConfigId->getFieldName(), 'manyToOne', 'Oro\\Bundle\\AttachmentBundle\\Entity\\File');
 }
Ejemplo n.º 9
0
 /**
  * @param string        $scope
  * @param FieldConfigId $fieldId
  *
  * @return ConfigInterface
  */
 protected function getFieldConfig($scope, FieldConfigId $fieldId)
 {
     return $this->configManager->getProvider($scope)->getConfig($fieldId->getClassName(), $fieldId->getFieldName());
 }
 /**
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  *
  * @param array $config
  */
 protected function prepare($config)
 {
     $metadata = [];
     $fieldConfigs = [];
     foreach ($config as $entityClassName => $entityData) {
         $entityMetadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
         $entityMetadata->expects($this->any())->method('getName')->will($this->returnValue($entityClassName));
         $metadata[$entityClassName] = $entityMetadata;
         $fieldNames = [];
         $fieldTypes = [];
         $fieldIdentifiers = [];
         $configs = [];
         foreach ($entityData['fields'] as $fieldName => $fieldData) {
             $fieldNames[] = $fieldName;
             $fieldTypes[] = [$fieldName, $fieldData['type']];
             $fieldIdentifiers[] = [$fieldName, isset($fieldData['identifier']) ? $fieldData['identifier'] : false];
             $configId = new FieldConfigId('extend', $entityClassName, $fieldName, $fieldData['type']);
             $configs[] = new Config($configId);
         }
         $fieldConfigs[$entityClassName] = $configs;
         $entityMetadata->expects($this->any())->method('getFieldNames')->will($this->returnValue($fieldNames));
         $entityMetadata->expects($this->any())->method('hasField')->willReturnCallback(function ($name) use($fieldNames) {
             return in_array($name, $fieldNames, true);
         });
         $entityMetadata->expects($this->any())->method('isIdentifier')->will($this->returnValueMap($fieldIdentifiers));
         $relNames = [];
         $mappings = [];
         if (isset($entityData['relations'])) {
             $relTargetClasses = [];
             foreach ($entityData['relations'] as $relName => $relData) {
                 $type = $relData['type'];
                 $relTargetClass = $relData['target_class'];
                 if ($type === 'ref-one') {
                     $mappings[$relName] = $relData;
                 }
                 $fieldTypes[] = [$relName, $type];
                 $relNames[] = $relName;
                 $relTargetClasses[] = [$relName, $relTargetClass];
             }
             $entityMetadata->expects($this->any())->method('getAssociationTargetClass')->will($this->returnValueMap($relTargetClasses));
             $entityMetadata->expects($this->any())->method('getAssociationMappedByTargetField')->will($this->returnValue('id'));
         }
         $entityMetadata->expects($this->any())->method('getAssociationNames')->will($this->returnValue($relNames));
         $entityMetadata->expects($this->any())->method('hasAssociation')->willReturnCallback(function ($name) use($relNames) {
             return in_array($name, $relNames, true);
         });
         if (isset($entityData['unidirectional_relations'])) {
             foreach ($entityData['unidirectional_relations'] as $relName => $relData) {
                 $fieldTypes[] = [$relName, $relData['type']];
                 $relData['fieldName'] = $relName;
                 $relData['isOwningSide'] = true;
                 $relData['inversedBy'] = null;
                 $relData['sourceEntity'] = $entityClassName;
                 unset($relData['config']);
                 $mappings[$relName] = $relData;
             }
             $entityMetadata->expects($this->any())->method('getAssociationMappings')->will($this->returnValue($mappings));
         }
         $entityMetadata->expects($this->any())->method('isSingleValuedAssociation')->will($this->returnCallback(function ($field) use($mappings) {
             return !empty($mappings[$field]);
         }));
         $entityMetadata->expects($this->any())->method('getTypeOfField')->will($this->returnValueMap($fieldTypes));
     }
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $metadataFactory = $this->getMock('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
     $em->expects($this->any())->method('getMetadataFactory')->will($this->returnValue($metadataFactory));
     $metadataFactory->expects($this->any())->method('getMetadataFor')->will($this->returnCallback(function ($entityClassName) use(&$metadata) {
         return $metadata[$entityClassName];
     }));
     $this->doctrine->expects($this->any())->method('getManagerForClass')->with($this->isType('string'))->will($this->returnValue($em));
     $this->extendConfigProvider->expects($this->any())->method('getConfigs')->will($this->returnCallback(function ($className) use($fieldConfigs) {
         return $fieldConfigs[$className];
     }));
     $this->entityConfigProvider->expects($this->any())->method('hasConfig')->will($this->returnCallback(function ($className, $fieldName) use(&$config) {
         if (isset($config[$className])) {
             if ($fieldName === null) {
                 return true;
             }
             if (isset($config[$className]['fields'][$fieldName]['config'])) {
                 return true;
             }
             if (isset($config[$className]['relations'][$fieldName]['config'])) {
                 return true;
             }
             if (isset($config[$className]['unidirectional_relations'][$fieldName]['config'])) {
                 return true;
             }
         }
         return false;
     }));
     $this->entityConfigProvider->expects($this->any())->method('getConfig')->will($this->returnCallback(function ($className, $fieldName) use(&$config) {
         if (isset($config[$className])) {
             if ($fieldName === null) {
                 return $this->getEntityConfig($className, $config[$className]['config']);
             }
             if (isset($config[$className]['fields'][$fieldName]['config'])) {
                 return $this->getEntityFieldConfig($className, $fieldName, $config[$className]['fields'][$fieldName]['type'], $config[$className]['fields'][$fieldName]['config']);
             }
             if (isset($config[$className]['relations'][$fieldName]['config'])) {
                 return $this->getEntityFieldConfig($className, $fieldName, $config[$className]['relations'][$fieldName]['type'], $config[$className]['relations'][$fieldName]['config']);
             }
             if (isset($config[$className]['unidirectional_relations'][$fieldName]['config'])) {
                 return $this->getEntityFieldConfig($className, $fieldName, $config[$className]['unidirectional_relations'][$fieldName]['type'], $config[$className]['unidirectional_relations'][$fieldName]['config']);
             }
         }
         return null;
     }));
     $this->extendConfigProvider->expects($this->any())->method('hasConfig')->will($this->returnCallback(function ($className, $fieldName) use(&$config) {
         if (isset($config[$className])) {
             if ($fieldName === null) {
                 return true;
             }
             if (isset($config[$className]['fields'][$fieldName]['config'])) {
                 return true;
             }
             if (isset($config[$className]['relations'][$fieldName]['config'])) {
                 return true;
             }
             if (isset($config[$className]['unidirectional_relations'][$fieldName]['config'])) {
                 return true;
             }
         }
         return false;
     }));
     $this->extendConfigProvider->expects($this->any())->method('getConfig')->will($this->returnCallback(function ($className, $fieldName) use(&$config) {
         if (isset($config[$className])) {
             if ($fieldName === null) {
                 return $this->getExtendEntityConfig($className, $config[$className]['config']);
             }
             if (isset($config[$className]['fields'][$fieldName]['config'])) {
                 return $this->getExtendFieldConfig($className, $fieldName, $config[$className]['fields'][$fieldName]['type'], $config[$className]['fields'][$fieldName]['config']);
             }
             if (isset($config[$className]['relations'][$fieldName]['config'])) {
                 return $this->getExtendFieldConfig($className, $fieldName, $config[$className]['relations'][$fieldName]['type'], $config[$className]['relations'][$fieldName]['config']);
             }
             if (isset($config[$className]['unidirectional_relations'][$fieldName]['config'])) {
                 return $this->getExtendFieldConfig($className, $fieldName, $config[$className]['unidirectional_relations'][$fieldName]['type'], $config[$className]['unidirectional_relations'][$fieldName]['config']);
             }
         }
         return null;
     }));
     $this->extendConfigProvider->expects($this->any())->method('getConfigById')->will($this->returnCallback(function (EntityConfigId $configId) use(&$config) {
         $className = $configId->getClassname();
         if (isset($config[$className])) {
             return $this->getExtendEntityConfig($className, $config[$className]['config']);
         }
         return null;
     }));
     $this->extendConfigProvider->expects($this->any())->method('getId')->will($this->returnCallback(function ($className, $fieldName) use(&$config) {
         if (isset($config[$className])) {
             if (isset($config[$className]['fields'][$fieldName]['config'])) {
                 return new FieldConfigId('extend', $className, $fieldName, $config[$className]['fields'][$fieldName]['type']);
             }
             if (isset($config[$className]['relations'][$fieldName]['config'])) {
                 return new FieldConfigId('extend', $className, $fieldName, $config[$className]['relations'][$fieldName]['type']);
             }
             if (isset($config[$className]['unidirectional_relations'][$fieldName]['config'])) {
                 return new FieldConfigId('extend', $className, $fieldName, $config[$className]['unidirectional_relations'][$fieldName]['type']);
             }
         }
         return null;
     }));
 }
 protected function renameExtendField(Schema $schema, QueryBag $queries, Table $table, FieldConfigId $fieldConfigId, ConfigManager $configManager, EntityMetadataHelper $entityMetadataHelper)
 {
     switch ($fieldConfigId->getFieldType()) {
         case RelationType::MANY_TO_ONE:
             $this->renameManyToOneExtendField($schema, $queries, $table, $fieldConfigId->getFieldName());
             break;
         case RelationType::ONE_TO_MANY:
             $config = $configManager->getConfig($fieldConfigId);
             $targetEntityClassName = $config->get('target_entity');
             $this->renameOneToManyExtendField($schema, $queries, $table, $fieldConfigId->getFieldName(), $targetEntityClassName, $entityMetadataHelper);
             break;
         case RelationType::MANY_TO_MANY:
             break;
         default:
             $oldColumnName = 'field_' . $fieldConfigId->getFieldName();
             if ($table->hasColumn($oldColumnName)) {
                 $this->renameExtension->renameColumn($schema, $queries, $table, $oldColumnName, $fieldConfigId->getFieldName());
             }
             break;
     }
 }
 /**
  * @param ConfigInterface $fieldConfig
  */
 protected function createSelfRelation(ConfigInterface $fieldConfig)
 {
     /** @var FieldConfigId $fieldConfigId */
     $fieldConfigId = $fieldConfig->getId();
     $targetEntityClass = $fieldConfig->get('target_entity');
     $selfFieldId = $selfFieldId = new FieldConfigId('extend', $fieldConfigId->getClassName(), $fieldConfigId->getFieldName(), $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType()));
     $targetFieldId = false;
     $owner = true;
     $targetOwner = false;
     if (in_array($selfFieldId->getFieldType(), RelationType::$toManyRelations, true)) {
         $classNameArray = explode('\\', $selfFieldId->getClassName());
         $relationFieldName = strtolower(array_pop($classNameArray)) . '_' . $selfFieldId->getFieldName();
         if ($selfFieldId->getFieldType() === RelationType::ONE_TO_MANY) {
             $owner = false;
             $targetOwner = true;
         }
         $targetFieldId = new FieldConfigId('extend', $targetEntityClass, $relationFieldName, ExtendHelper::getReverseRelationType($selfFieldId->getFieldType()));
     }
     $relationKey = ExtendHelper::buildRelationKey($selfFieldId->getClassName(), $selfFieldId->getFieldName(), $selfFieldId->getFieldType(), $targetEntityClass);
     $selfConfig = $this->extendConfigProvider->getConfig($selfFieldId->getClassName());
     $selfRelationConfig = ['field_id' => $selfFieldId, 'owner' => $owner, 'target_entity' => $targetEntityClass, 'target_field_id' => $targetFieldId];
     if ($fieldConfig->has('cascade')) {
         $selfRelationConfig['cascade'] = $fieldConfig->get('cascade');
     }
     $selfRelations = $selfConfig->get('relation', false, []);
     $selfRelations[$relationKey] = $selfRelationConfig;
     $selfConfig->set('relation', $selfRelations);
     $this->configManager->persist($selfConfig);
     $targetConfig = $this->extendConfigProvider->getConfig($targetEntityClass);
     $targetRelationConfig = ['field_id' => $targetFieldId, 'owner' => $targetOwner, 'target_entity' => $selfFieldId->getClassName(), 'target_field_id' => $selfFieldId];
     $targetRelations = $targetConfig->get('relation', false, []);
     $targetRelations[$relationKey] = $targetRelationConfig;
     $targetConfig->set('relation', $targetRelations);
     $this->configManager->persist($targetConfig);
     $fieldConfig->set('relation_key', $relationKey);
     $this->configManager->persist($fieldConfig);
 }
Ejemplo n.º 13
0
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(array('attr' => array('class' => 'extend-rel-target-name'), 'label' => 'Target entity', 'empty_value' => $this->targetEntity ? false : 'Please choice target entity...', 'read_only' => (bool) $this->targetEntity, 'choices' => $this->getEntityChoiceList($this->configId->getClassName(), $this->configId->getFieldType())));
 }
 /**
  * @param string $code
  * @param $label
  * @param FieldConfigId $fieldConfig
  *
  * @return array
  */
 protected function createFieldArrayDefinition($code, $label, FieldConfigId $fieldConfig)
 {
     return [$code => ['type' => 'field', 'label' => $label, 'field_name' => $code, 'filter_type' => $this->filterMap[$fieldConfig->getFieldType()], 'required' => false, 'sortable' => true, 'filterable' => true, 'show_filter' => true]];
 }
Ejemplo n.º 15
0
 /**
  * @param object $entity
  * @param FieldConfigId $fieldConfig
  * @return OptionSetRelation[]
  */
 protected function getValueForOptionSet($entity, FieldConfigId $fieldConfig)
 {
     /** @var $optionSetRepository OptionSetRelationRepository */
     $optionSetRepository = $this->configManager->getEntityManager()->getRepository(OptionSetRelation::ENTITY_NAME);
     $model = $this->configManager->getConfigFieldModel($fieldConfig->getClassName(), $fieldConfig->getFieldName());
     $value = $optionSetRepository->findByFieldId($model->getId(), $entity->getId());
     array_walk($value, function (OptionSetRelation &$item) {
         $item = array('title' => $item->getOption()->getLabel());
     });
     $value['values'] = $value;
     return $value;
 }
Ejemplo n.º 16
0
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setDefaults(array('attr' => array('class' => 'extend-rel-target-name'), 'label' => 'oro.entity_extend.form.target_entity', 'empty_value' => $this->targetEntity ? null : '', 'read_only' => (bool) $this->targetEntity, 'choices' => $this->getEntityChoiceList($this->configId->getClassName(), $this->configId->getFieldType()), 'choice_attr' => function ($choice) {
         return $this->getChoiceAttributes($choice);
     }, 'configs' => array('allowClear' => true, 'placeholder' => 'oro.entity.form.choose_entity', 'result_template_twig' => 'OroEntityBundle:Choice:entity/result.html.twig', 'selection_template_twig' => 'OroEntityBundle:Choice:entity/selection.html.twig')));
 }
Ejemplo n.º 17
0
 public function testDeleteFieldConfig()
 {
     $configId = new FieldConfigId(self::SCOPE, self::ENTITY_CLASS, self::FIELD_NAME, self::FIELD_TYPE);
     $cacheKey = self::ENTITY_CLASS . '.' . self::FIELD_NAME;
     $this->cache->expects($this->at(0))->method('delete')->with(ConfigCache::FIELD_NAMES_KEY . self::ENTITY_CLASS)->willReturn(true);
     $this->cache->expects($this->at(1))->method('delete')->with($cacheKey)->willReturn(true);
     $this->assertTrue($this->configCache->deleteFieldConfig($configId->getClassName(), $configId->getFieldName()));
 }
Ejemplo n.º 18
0
 /**
  * @param array $options
  * @param ConfigInterface $extendConfig
  * @param FieldConfigId $fieldConfigId
  *
  * @return array
  */
 protected function addConstraintsToOptions(array $options, ConfigInterface $extendConfig, FieldConfigId $fieldConfigId)
 {
     switch ($fieldConfigId->getFieldType()) {
         case 'decimal':
             $options['constraints'] = [new Decimal(['precision' => $extendConfig->get('precision'), 'scale' => $extendConfig->get('scale')])];
             break;
         case 'string':
             $length = $extendConfig->get('length') ?: 255;
             $options['constraints'] = [new Length(['max' => $length])];
             break;
     }
     return $options;
 }
Ejemplo n.º 19
0
 /**
  * @param ClassMetadataBuilder $metadataBuilder
  * @param FieldConfigId        $fieldId
  * @param string               $targetEntity
  */
 protected function buildDefaultRelation(ClassMetadataBuilder $metadataBuilder, FieldConfigId $fieldId, $targetEntity)
 {
     $builder = $metadataBuilder->createOneToOne(ExtendConfigDumper::DEFAULT_PREFIX . $fieldId->getFieldName(), $targetEntity);
     $builder->addJoinColumn($this->nameGenerator->generateRelationDefaultColumnName($fieldId->getFieldName()), 'id', true, false, 'SET NULL');
     $builder->build();
 }
Ejemplo n.º 20
0
 /**
  * @param FieldConfigId $fieldId
  *
  * @return ConfigInterface
  */
 protected function getFieldConfig(FieldConfigId $fieldId)
 {
     return $this->configManager->getFieldConfig('extend', $fieldId->getClassName(), $fieldId->getFieldName());
 }
Ejemplo n.º 21
0
 public function testClearFieldCache()
 {
     $configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'field');
     $this->configCache->expects($this->once())->method('deleteFieldConfig')->with($configId->getClassName(), $configId->getFieldName());
     $this->configManager->clearCache($configId);
 }
Ejemplo n.º 22
0
 /**
  * Changes a type of a field
  *
  * @param string $className
  * @param string $fieldName
  * @param string $newFieldName
  * @return bool TRUE if the name was changed; otherwise, FALSE
  */
 public function changeFieldName($className, $fieldName, $newFieldName)
 {
     $result = $this->modelManager->changeFieldName($className, $fieldName, $newFieldName);
     if ($result) {
         $this->eventDispatcher->dispatch(Events::RENAME_FIELD, new RenameFieldEvent($className, $fieldName, $newFieldName, $this));
         foreach ($this->getProviders() as $provider) {
             /** @var FieldConfigId $newConfigId */
             $newConfigId = $this->getId($provider->getScope(), $className, $newFieldName);
             $newConfigKey = $this->buildConfigKey($newConfigId);
             $configId = new FieldConfigId($newConfigId->getScope(), $newConfigId->getClassName(), $fieldName, $newConfigId->getFieldType());
             $cachedConfig = $this->cache->getFieldConfig($configId->getScope(), $configId->getClassName(), $configId->getFieldName(), true);
             if ($cachedConfig) {
                 $this->cache->saveConfig($this->changeConfigFieldName($cachedConfig, $newFieldName), true);
                 $this->cache->deleteFieldConfig($configId->getClassName(), $configId->getFieldName(), true);
             }
             $configKey = $this->buildConfigKey($configId);
             if (isset($this->persistConfigs[$configKey])) {
                 $this->persistConfigs[$newConfigKey] = $this->changeConfigFieldName($this->persistConfigs[$configKey], $newFieldName);
                 unset($this->persistConfigs[$configKey]);
             }
             if (isset($this->originalConfigs[$configKey])) {
                 $this->originalConfigs[$newConfigKey] = $this->changeConfigFieldName($this->originalConfigs[$configKey], $newFieldName);
                 unset($this->originalConfigs[$configKey]);
             }
             if (isset($this->configChangeSets[$configKey])) {
                 $this->configChangeSets[$newConfigKey] = $this->configChangeSets[$configKey];
                 unset($this->configChangeSets[$configKey]);
             }
         }
     }
     return $result;
 }