/** * {@inheritdoc} */ public function preUpdate() { $extendConfigProvider = $this->configManager->getProvider('extend'); $entityConfigs = $extendConfigProvider->getConfigs(); foreach ($entityConfigs as $entityConfig) { if (!$entityConfig->is('is_extend')) { continue; } $fieldConfigs = $extendConfigProvider->getConfigs($entityConfig->getId()->getClassName()); foreach ($fieldConfigs as $fieldConfig) { if (!$fieldConfig->in('state', [ExtendScope::STATE_NEW, ExtendScope::STATE_UPDATE])) { continue; } /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $fieldConfig->getId(); if (in_array($fieldConfigId->getFieldType(), ['file', 'image'])) { $cascade = $fieldConfig->get('cascade', false, []); if (!in_array('persist', $cascade, true)) { $cascade[] = 'persist'; } $this->relationBuilder->addManyToOneRelation($entityConfig, 'Oro\\Bundle\\AttachmentBundle\\Entity\\File', $fieldConfigId->getFieldName(), 'id', ['extend' => ['cascade' => $cascade], 'importexport' => ['process_as_scalar' => true]], $fieldConfigId->getFieldType()); } } } }
/** * {@inheritdoc} */ public function preUpdate() { $extendConfigProvider = $this->configManager->getProvider('extend'); $entityConfigs = $extendConfigProvider->getConfigs(); foreach ($entityConfigs as $entityConfig) { if (!$entityConfig->is('is_extend')) { continue; } $fieldConfigs = $extendConfigProvider->getConfigs($entityConfig->getId()->getClassName()); foreach ($fieldConfigs as $fieldConfig) { if (!$fieldConfig->is('state', ExtendScope::STATE_NEW)) { continue; } /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $fieldConfig->getId(); if (in_array($fieldConfigId->getFieldType(), ['file', 'image'])) { // create a relation $relationKey = $this->relationBuilder->addManyToOneRelation($entityConfig, 'Oro\\Bundle\\AttachmentBundle\\Entity\\File', $fieldConfigId->getFieldName(), 'id', ['importexport' => ['process_as_scalar' => true]], $fieldConfigId->getFieldType()); // set cascade persist $relations = $entityConfig->get('relation'); $cascade = isset($relations[$relationKey]['cascade']) ? $relations[$relationKey]['cascade'] : []; $cascade[] = 'persist'; $relations[$relationKey]['cascade'] = $cascade; $entityConfig->set('relation', $relations); $extendConfigProvider->persist($entityConfig); } } } }
/** * @param ConfigInterface $entityConfig * @param string $targetEntityClassName * @param string $relationName */ protected function createOwnerRelation(ConfigInterface $entityConfig, $targetEntityClassName, $relationName) { $relationKey = ExtendHelper::buildRelationKey($entityConfig->getId()->getClassName(), $relationName, 'manyToOne', $this->ownershipMetadataProvider->getOrganizationClass()); if (!isset($entityConfig->get('relation')[$relationKey])) { $this->relationBuilder->addManyToOneRelation($entityConfig, $targetEntityClassName, $relationName, 'id', ['entity' => ['label' => 'oro.custom_entity.' . $relationName . '.label', 'description' => 'oro.custom_entity.' . $relationName . '.description'], 'view' => ['is_displayable' => false], 'form' => ['is_enabled' => false], 'dataaudit' => ['auditable' => true]]); } }
/** * @param string $sourceEntityClass * @param string $targetEntityClass * @param string $associationKind */ public function createManyToOneAssociation($sourceEntityClass, $targetEntityClass, $associationKind) { $relationName = ExtendHelper::buildAssociationName($targetEntityClass, $associationKind); $entityConfigProvider = $this->configManager->getProvider('entity'); $targetEntityConfig = $entityConfigProvider->getConfig($targetEntityClass); $label = $targetEntityConfig->get('label', false, ConfigHelper::getTranslationKey('entity', 'label', $targetEntityClass, $relationName)); $description = ConfigHelper::getTranslationKey('entity', 'description', $targetEntityClass, $relationName); $targetEntityPrimaryKeyColumns = $this->getPrimaryKeyColumnNames($targetEntityClass); $targetFieldName = array_shift($targetEntityPrimaryKeyColumns); // add relation to owning entity $this->relationBuilder->addManyToOneRelation($this->configManager->getProvider('extend')->getConfig($sourceEntityClass), $targetEntityClass, $relationName, $targetFieldName, ['entity' => ['label' => $label, 'description' => $description], 'view' => ['is_displayable' => false], 'form' => ['is_enabled' => false]]); }
/** * @param string $sourceEntityClass * @param string $targetEntityClass * @param string $associationKind */ public function createManyToOneAssociation($sourceEntityClass, $targetEntityClass, $associationKind) { $relationName = ExtendHelper::buildAssociationName($targetEntityClass, $associationKind); $extendConfigProvider = $this->configManager->getProvider('extend'); $targetEntityPrimaryKeyColumns = $this->getPrimaryKeyColumnNames($targetEntityClass); $targetFieldName = reset($targetEntityPrimaryKeyColumns); // add relation to owning entity $this->relationBuilder->addManyToOneRelation($extendConfigProvider->getConfig($sourceEntityClass), $targetEntityClass, $relationName, $targetFieldName); // update attributes for new association $fieldConfig = $extendConfigProvider->getConfig($sourceEntityClass, $relationName); if ($fieldConfig->is('state', ExtendScope::STATE_NEW)) { $targetEntityConfig = $this->configManager->getProvider('entity')->getConfig($targetEntityClass); $this->relationBuilder->updateFieldConfigs($sourceEntityClass, $relationName, ['entity' => ['label' => $this->getAssociationLabel('label', $sourceEntityClass, $relationName, $targetEntityConfig), 'description' => $this->getAssociationLabel('description', $sourceEntityClass, $relationName, $targetEntityConfig)], 'view' => ['is_displayable' => false], 'form' => ['is_enabled' => false]]); } }
public function testAddManyToOneRelationTargetSide() { $relationName = 'testRelation'; $relationKey = 'manyToOne|Test\\SourceEntity|Test\\TargetEntity|testRelation'; $extendConfig = new Config(new EntityConfigId('extend', self::TARGET_CLASS)); $expectedExtendConfig = new Config(new EntityConfigId('extend', self::TARGET_CLASS)); $expectedExtendConfig->set('relation', [$relationKey => ['assign' => false, 'target_field_id' => new FieldConfigId('extend', self::SOURCE_CLASS, $relationName, 'manyToOne'), 'owner' => false, 'target_entity' => self::SOURCE_CLASS, 'field_id' => false]]); $extendConfigProvider = $this->getConfigProviderMock(); $extendConfigProvider->expects($this->once())->method('getConfig')->with(self::TARGET_CLASS)->will($this->returnValue($extendConfig)); $extendConfigProvider->expects($this->once())->method('persist')->with($this->identicalTo($extendConfig)); $this->configManager->expects($this->any())->method('getProvider')->will($this->returnValueMap([['extend', $extendConfigProvider]])); $this->builder->addManyToOneRelationTargetSide(self::TARGET_CLASS, self::SOURCE_CLASS, $relationName, $relationKey); $this->assertEquals($expectedExtendConfig, $extendConfig); }
/** * @param string $enumValueClassName The full class name of an entity is used to store enum values * @param string $enumCode The unique identifier of an enum * @param bool $isMultiple Indicates whether several options can be selected for this enum * or it supports only one selected option * @param bool|null $isPublic Indicates whether this enum can be used by any entity or * it is designed to use in one entity only * NULL means unspecified. In this case this attribute will not be * changed for existing enum entity and will be set to FALSE * for new enum entity */ protected function createEnumValueConfigEntityModel($enumValueClassName, $enumCode, $isMultiple, $isPublic) { if ($this->configManager->hasConfigEntityModel($enumValueClassName)) { if (null !== $isPublic) { $this->relationBuilder->updateEntityConfigs($enumValueClassName, ['enum' => ['public' => $isPublic]]); } return; } if (null === $isPublic) { $isPublic = false; } // create entity $this->configManager->createConfigEntityModel($enumValueClassName, ConfigModelManager::MODE_HIDDEN); $this->relationBuilder->updateEntityConfigs($enumValueClassName, ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode), 'plural_label' => ExtendHelper::getEnumTranslationKey('plural_label', $enumCode), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode)], 'extend' => ['owner' => ExtendScope::OWNER_SYSTEM, 'is_extend' => true, 'table' => $this->nameGenerator->generateEnumTableName($enumCode, true), 'inherit' => ExtendHelper::BASE_ENUM_VALUE_CLASS], 'enum' => ['code' => $enumCode, 'public' => $isPublic, 'multiple' => $isMultiple]]); // create fields $this->configManager->createConfigFieldModel($enumValueClassName, 'id', 'string'); $this->relationBuilder->updateFieldConfigs($enumValueClassName, 'id', ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'id'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'id')], 'importexport' => ['identity' => true]]); $this->configManager->createConfigFieldModel($enumValueClassName, 'name', 'string'); $this->relationBuilder->updateFieldConfigs($enumValueClassName, 'name', ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'name'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'name')], 'datagrid' => ['is_visible' => false]]); $this->configManager->createConfigFieldModel($enumValueClassName, 'priority', 'integer'); $this->relationBuilder->updateFieldConfigs($enumValueClassName, 'priority', ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'priority'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'priority')], 'datagrid' => ['is_visible' => false]]); $this->configManager->createConfigFieldModel($enumValueClassName, 'default', 'boolean'); $this->relationBuilder->updateFieldConfigs($enumValueClassName, 'default', ['entity' => ['label' => ExtendHelper::getEnumTranslationKey('label', $enumCode, 'default'), 'description' => ExtendHelper::getEnumTranslationKey('description', $enumCode, 'default')], 'datagrid' => ['is_visible' => false]]); }
/** * @param ConfigInterface $entityConfig * @param string $targetEntityClassName * @param string $relationName */ protected function createOwnerRelation(ConfigInterface $entityConfig, $targetEntityClassName, $relationName) { $this->relationBuilder->addManyToOneRelation($entityConfig, $targetEntityClassName, $relationName, 'id', ['entity' => ['label' => 'oro.custom_entity.' . $relationName . '.label', 'description' => 'oro.custom_entity.' . $relationName . '.description'], 'view' => ['is_displayable' => false], 'form' => ['is_enabled' => false], 'dataaudit' => ['auditable' => true]]); }