本文整理汇总了PHP中Oro\Bundle\EntityConfigBundle\Config\ConfigManager::createConfigFieldModel方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigManager::createConfigFieldModel方法的具体用法?PHP ConfigManager::createConfigFieldModel怎么用?PHP ConfigManager::createConfigFieldModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Oro\Bundle\EntityConfigBundle\Config\ConfigManager
的用法示例。
在下文中一共展示了ConfigManager::createConfigFieldModel方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addManyToOneRelation
/**
* @param ConfigInterface $sourceEntityConfig The 'extend' config of the source entity
* @param string $targetEntityName
* @param string $relationName
* @param string $targetFieldName A field name is used to show related entity
* @param array $options
* @param string $fieldType The field type. By default the field type is manyToOne,
* but you can specify another type if it is based on manyToOne.
* In this case this type should be registered
* in entity_extend.yml under underlying_types section
*
* @return string The relation key
*/
public function addManyToOneRelation(ConfigInterface $sourceEntityConfig, $targetEntityName, $relationName, $targetFieldName, $options = [], $fieldType = 'manyToOne')
{
$sourceEntityName = $sourceEntityConfig->getId()->getClassName();
$relationKey = ExtendHelper::buildRelationKey($sourceEntityName, $relationName, 'manyToOne', $targetEntityName);
// add a relation field config
if (!$this->configManager->hasConfigFieldModel($sourceEntityName, $relationName)) {
$this->configManager->createConfigFieldModel($sourceEntityName, $relationName, $fieldType);
$options['extend']['state'] = ExtendScope::STATE_NEW;
} else {
$configFieldModel = $this->configManager->getConfigFieldModel($sourceEntityName, $relationName);
if ($configFieldModel->getType() !== $fieldType) {
$this->configManager->changeFieldType($sourceEntityName, $relationName, $fieldType);
}
}
$options['extend']['is_extend'] = true;
$options['extend']['relation_key'] = $relationKey;
$options['extend']['target_entity'] = $targetEntityName;
$options['extend']['target_field'] = $targetFieldName;
$this->updateFieldConfigs($sourceEntityName, $relationName, $options);
// add relation to config
$relations = $sourceEntityConfig->get('relation', false, []);
if (!isset($relations[$relationKey])) {
$relations[$relationKey] = ['assign' => false, 'field_id' => new FieldConfigId('extend', $sourceEntityName, $relationName, 'manyToOne'), 'owner' => true, 'target_entity' => $targetEntityName, 'target_field_id' => false];
$sourceEntityConfig->set('relation', $relations);
$extendConfigProvider = $this->configManager->getProvider('extend');
$extendConfigProvider->persist($sourceEntityConfig);
}
return $relationKey;
}
示例2: writeItem
/**
* @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;
}
示例3: testCreateConfigFieldModel
public function testCreateConfigFieldModel()
{
$configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int');
$model = $this->createFieldConfigModel($this->createEntityConfigModel(self::ENTITY_CLASS), 'id', 'int');
$this->modelManager->expects($this->once())->method('findFieldModel')->with(self::ENTITY_CLASS, 'id')->will($this->returnValue(null));
$this->modelManager->expects($this->once())->method('createFieldModel')->with(self::ENTITY_CLASS, 'id', 'int', ConfigModelManager::MODE_DEFAULT)->will($this->returnValue($model));
$metadata = new EntityMetadata(self::ENTITY_CLASS);
$idFieldMetadata = new FieldMetadata(self::ENTITY_CLASS, 'id');
$metadata->addPropertyMetadata($idFieldMetadata);
$this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->will($this->returnValue($metadata));
$idFieldMetadata->defaultValues['entity'] = ['translatable' => 'labelVal', 'other' => 'otherVal'];
$this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->will($this->returnValue($metadata));
$propertyConfigContainer = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\PropertyConfigContainer')->disableOriginalConstructor()->getMock();
$propertyConfigContainer->expects($this->once())->method('getDefaultValues')->with(PropertyConfigContainer::TYPE_FIELD, 'int')->will($this->returnValue(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']));
$propertyConfigContainer->expects($this->once())->method('getTranslatableValues')->with(PropertyConfigContainer::TYPE_FIELD)->will($this->returnValue(['translatable', 'translatable10', 'auto_generated']));
$this->configProvider->expects($this->any())->method('getPropertyConfig')->will($this->returnValue($propertyConfigContainer));
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(Events::NEW_FIELD_CONFIG, new FieldConfigEvent(self::ENTITY_CLASS, 'id', $this->configManager));
$config = new Config($configId);
$config->set('other10', 'otherVal10');
$config->set('translatable10', 'labelVal10');
$config->set('other', 'otherVal');
$config->set('translatable', 'labelVal');
$config->set('auto_generated', 'oro.entityconfig.tests.unit.fixture.demoentity.id.auto_generated');
$result = $this->configManager->createConfigFieldModel(self::ENTITY_CLASS, 'id', 'int');
$this->assertEquals($model, $result);
$this->assertEquals([$config], $this->configManager->getUpdateConfig());
// test that a config for a created model is stored in a local cache
$result = $this->configManager->getConfig($configId);
$this->assertEquals($config, $result);
}
示例4: addRelationField
/**
* @param string $entityClass
* @param string $fieldName
* @param string $label
* @param string $description
* @param string $targetEntity
* @param string $targetField
*/
protected function addRelationField($entityClass, $fieldName, $label, $description, $targetEntity, $targetField)
{
$this->configManager->createConfigFieldModel($entityClass, $fieldName, 'manyToOne');
$entityConfigProvider = $this->configManager->getProvider('entity');
$entityFieldConfig = $entityConfigProvider->getConfig($entityClass, $fieldName);
$entityFieldConfig->set('label', $label);
$entityFieldConfig->set('description', $description);
$extendConfigProvider = $this->configManager->getProvider('extend');
$extendFieldConfig = $extendConfigProvider->getConfig($entityClass, $fieldName);
$extendFieldConfig->set('owner', ExtendScope::OWNER_CUSTOM);
$extendFieldConfig->set('state', ExtendScope::STATE_NEW);
$extendFieldConfig->set('is_extend', true);
$extendFieldConfig->set('target_entity', $targetEntity);
$extendFieldConfig->set('target_field', $targetField);
$extendFieldConfig->set('relation_key', ExtendHelper::buildRelationKey($entityClass, $targetField, 'manyToOne', $targetEntity));
$formConfigProvider = $this->configManager->getProvider('form');
$formFieldConfig = $formConfigProvider->getConfig($entityClass, $fieldName);
$formFieldConfig->set('is_enabled', false);
$viewConfigProvider = $this->configManager->getProvider('view');
$viewFieldConfig = $viewConfigProvider->getConfig($entityClass, $fieldName);
$viewFieldConfig->set('is_displayable', false);
$importExportConfigProvider = $this->configManager->getProvider('importexport');
$importExportFieldConfig = $importExportConfigProvider->getConfig($entityClass, $fieldName);
$importExportFieldConfig->set('excluded', true);
}
示例5: loadFieldConfigs
/**
* @param string $className
* @param string $fieldName
* @param string $fieldType
* @param bool $force
*/
protected function loadFieldConfigs($className, $fieldName, $fieldType, $force)
{
if ($this->configManager->hasConfig($className, $fieldName)) {
$this->logger->info(sprintf('Update config for "%s" field.', $fieldName));
$this->configManager->updateConfigFieldModel($className, $fieldName, $force);
} else {
$this->logger->info(sprintf('Create config for "%s" field.', $fieldName));
$this->configManager->createConfigFieldModel($className, $fieldName, $fieldType);
}
}
示例6: preUpdate
/**
* {@inheritdoc}
*/
public function preUpdate()
{
/** @var ConfigProvider $extendConfigProvider */
$extendConfigProvider = $this->configManager->getProvider('extend');
/** @var ConfigProvider $activityConfigProvider */
$activityConfigProvider = $this->configManager->getProvider('activity');
$contactingActivityClasses = $this->activityContactProvider->getSupportedActivityClasses();
$entityConfigs = $extendConfigProvider->getConfigs();
foreach ($entityConfigs as $entityConfig) {
if ($entityConfig->is('is_extend')) {
$entityClassName = $entityConfig->getId()->getClassName();
// Skipp excluded entity
if (TargetExcludeList::isExcluded($entityClassName)) {
continue;
}
/**
* Check if entity has any activity from contact activities group
*/
$entityActivities = $activityConfigProvider->getConfig($entityClassName)->get('activities');
if (!$entityActivities || !array_intersect($contactingActivityClasses, $entityActivities)) {
continue;
}
/** @var ConfigInterface[] $entityFields */
$entityFields = $extendConfigProvider->getConfigs($entityClassName);
$entityFieldNames = array_map(function (ConfigInterface $item) {
return $item->getId()->getFieldName();
}, $entityFields);
/**
* Check if entity already has all needed fields.
* If at least one is not present we should check and add it too.
*/
if (false === (bool) array_diff(array_keys(ActivityScope::$fieldsConfiguration), array_intersect($entityFieldNames, array_keys(ActivityScope::$fieldsConfiguration)))) {
continue;
}
foreach (ActivityScope::$fieldsConfiguration as $fieldName => $fieldConfig) {
if (!in_array($fieldName, $entityFieldNames)) {
$this->configManager->createConfigFieldModel($entityClassName, $fieldName, $fieldConfig['type'], $fieldConfig['mode']);
$this->updateConfigs($entityClassName, $fieldName, $fieldConfig['options']);
}
}
}
}
}
示例7: createFieldModel
/**
* @param string $className
* @param string $fieldName
* @param string $fieldType
* @param string $mode
* @param array $configs
* @param bool $isExtendEntity
* @throws \LogicException
*/
protected function createFieldModel($className, $fieldName, $fieldType, $mode, array $configs, $isExtendEntity)
{
if (!$isExtendEntity && isset($configs['extend']['is_extend']) && $configs['extend']['is_extend']) {
throw new \LogicException(sprintf('An extend field "%s" cannot be added to non extend entity "%s".', $fieldName, $className));
}
$this->logger->info(sprintf('Create field "%s". Type: %s. Mode: %s. Entity: %s.', $fieldName, $fieldType, $mode, $className), ['configs' => $configs]);
$this->configManager->createConfigFieldModel($className, $fieldName, $fieldType, $mode);
$this->updateConfigs($configs, $className, $fieldName);
$extendConfigProvider = $this->configManager->getProvider('extend');
$extendConfig = $extendConfigProvider->getConfig($className, $fieldName);
$extendConfig->set('state', ExtendScope::STATE_NEW);
$this->configManager->persist($extendConfig);
}
示例8: createEntityModel
/**
* @param $entityName
* @param $entityConfig
* @return void
*/
protected function createEntityModel($entityName, $entityConfig)
{
$mode = isset($entityConfig['mode']) ? $entityConfig['mode'] : ConfigModelManager::MODE_DEFAULT;
$this->configManager->createConfigEntityModel($entityName, $mode);
if (class_exists($entityName)) {
$doctrineMetadata = $this->configManager->getEntityManager()->getClassMetadata($entityName);
foreach ($doctrineMetadata->getFieldNames() as $fieldName) {
$type = $doctrineMetadata->getTypeOfField($fieldName);
$this->configManager->createConfigFieldModel($doctrineMetadata->getName(), $fieldName, $type);
}
foreach ($doctrineMetadata->getAssociationNames() as $fieldName) {
$type = $doctrineMetadata->isSingleValuedAssociation($fieldName) ? 'ref-one' : 'ref-many';
$this->configManager->createConfigFieldModel($doctrineMetadata->getName(), $fieldName, $type);
}
}
}
示例9: testCreateConfigFieldModel
/**
* @dataProvider createConfigFieldModelProvider
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testCreateConfigFieldModel($mode, $hasMetadata, $metadataMode, $expectedMode, $cachedFields, $expectedSavedCachedFields)
{
$configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int');
$model = $this->createFieldConfigModel($this->createEntityConfigModel(self::ENTITY_CLASS), 'id', 'int');
$metadata = null;
if ($hasMetadata) {
$metadata = $this->getEntityMetadata(self::ENTITY_CLASS);
$idFieldMetadata = $this->getFieldMetadata(self::ENTITY_CLASS, 'id');
$idFieldMetadata->defaultValues['entity'] = ['translatable' => 'labelVal', 'other' => 'otherVal'];
$metadata->addPropertyMetadata($idFieldMetadata);
if (null !== $metadataMode) {
$idFieldMetadata->mode = $metadataMode;
}
}
$this->modelManager->expects($this->once())->method('findFieldModel')->with(self::ENTITY_CLASS, 'id')->willReturn(null);
$this->modelManager->expects($this->once())->method('createFieldModel')->with(self::ENTITY_CLASS, 'id', 'int', $expectedMode)->willReturn($model);
$this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->willReturn($metadata);
$this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->willReturn($metadata);
$propertyConfigContainer = $this->getPropertyConfigContainerMock();
$propertyConfigContainer->expects($this->once())->method('getDefaultValues')->with(PropertyConfigContainer::TYPE_FIELD, 'int')->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']);
$propertyConfigContainer->expects($this->once())->method('getTranslatableValues')->with(PropertyConfigContainer::TYPE_FIELD)->willReturn(['translatable', 'translatable10', 'auto_generated']);
$this->configProvider->expects($this->any())->method('getPropertyConfig')->willReturn($propertyConfigContainer);
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(Events::CREATE_FIELD, new FieldConfigEvent(self::ENTITY_CLASS, 'id', $this->configManager));
$config = $this->getConfig($configId, ['translatable' => 'oro.entityconfig.tests.unit.fixture.demoentity.id.translatable', 'other10' => 'otherVal10', 'translatable10' => 'labelVal10', 'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.id.auto_generated']);
if ($metadata) {
$config->set('other', 'otherVal');
$config->set('translatable', 'labelVal');
}
$this->configCache->expects($this->once())->method('saveConfig')->with($config, true);
$this->configCache->expects($this->once())->method('saveConfigurable')->with(true, self::ENTITY_CLASS, 'id', true);
$this->configCache->expects($this->once())->method('getFields')->with(self::ENTITY_CLASS, true)->willReturn($cachedFields);
if (null === $expectedSavedCachedFields) {
$this->configCache->expects($this->never())->method('saveFields');
} else {
$this->configCache->expects($this->once())->method('saveFields')->with(self::ENTITY_CLASS, $expectedSavedCachedFields, true);
}
$result = $this->configManager->createConfigFieldModel(self::ENTITY_CLASS, 'id', 'int', $mode);
$this->assertEquals($model, $result);
$this->assertEquals([$config], $this->configManager->getUpdateConfig());
}
示例10: testCreateConfigFieldModel
public function testCreateConfigFieldModel()
{
$configId = new FieldConfigId('entity', self::ENTITY_CLASS, 'id', 'int');
$model = $this->createFieldConfigModel($this->createEntityConfigModel(self::ENTITY_CLASS), 'id', 'int');
$metadata = $this->getEntityMetadata(self::ENTITY_CLASS);
$idFieldMetadata = $this->getFieldMetadata(self::ENTITY_CLASS, 'id');
$metadata->addPropertyMetadata($idFieldMetadata);
$this->modelManager->expects($this->once())->method('findFieldModel')->with(self::ENTITY_CLASS, 'id')->willReturn(null);
$this->modelManager->expects($this->once())->method('createFieldModel')->with(self::ENTITY_CLASS, 'id', 'int', ConfigModelManager::MODE_DEFAULT)->willReturn($model);
$this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->willReturn($metadata);
$idFieldMetadata->defaultValues['entity'] = ['translatable' => 'labelVal', 'other' => 'otherVal'];
$this->metadataFactory->expects($this->once())->method('getMetadataForClass')->with(self::ENTITY_CLASS)->willReturn($metadata);
$propertyConfigContainer = $this->getPropertyConfigContainerMock();
$propertyConfigContainer->expects($this->once())->method('getDefaultValues')->with(PropertyConfigContainer::TYPE_FIELD, 'int')->willReturn(['translatable10' => 'labelVal10', 'other10' => 'otherVal10']);
$propertyConfigContainer->expects($this->once())->method('getTranslatableValues')->with(PropertyConfigContainer::TYPE_FIELD)->willReturn(['translatable', 'translatable10', 'auto_generated']);
$this->configProvider->expects($this->any())->method('getPropertyConfig')->willReturn($propertyConfigContainer);
$this->eventDispatcher->expects($this->once())->method('dispatch')->with(Events::NEW_FIELD_CONFIG, new FieldConfigEvent(self::ENTITY_CLASS, 'id', $this->configManager));
$config = $this->getConfig($configId, ['other10' => 'otherVal10', 'translatable10' => 'labelVal10', 'other' => 'otherVal', 'translatable' => 'labelVal', 'auto_generated' => 'oro.entityconfig.tests.unit.fixture.demoentity.id.auto_generated']);
$this->configCache->expects($this->once())->method('saveConfig')->with($config, true);
$result = $this->configManager->createConfigFieldModel(self::ENTITY_CLASS, 'id', 'int');
$this->assertEquals($model, $result);
$this->assertEquals([$config], $this->configManager->getUpdateConfig());
}
示例11: createEnumValueConfigEntityModel
/**
* @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]]);
}