public function testCreateFieldModel() { $entityModel = $this->createEntityModel(self::TEST_ENTITY); $expectedResult = new FieldConfigModel(self::TEST_FIELD, 'int'); $expectedResult->setMode(ConfigModelManager::MODE_DEFAULT); $expectedResult->setEntity($entityModel); $this->createRepositoryMock([$entityModel], [UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED, UnitOfWork::STATE_MANAGED]); $result = $this->configModelManager->createFieldModel(self::TEST_ENTITY, self::TEST_FIELD, 'int', ConfigModelManager::MODE_DEFAULT); $this->assertEquals($expectedResult, $result); // test that the created model is stored in a local cache $this->assertSame($result, $this->configModelManager->getFieldModel(self::TEST_ENTITY, self::TEST_FIELD)); }
/** * @param string $className * @param string $fieldName * @param string $fieldType * @param string $mode * @return FieldConfigModel */ public function createConfigFieldModel($className, $fieldName, $fieldType, $mode = ConfigModelManager::MODE_DEFAULT) { if (!($fieldModel = $this->modelManager->findModel($className, $fieldName))) { $fieldModel = $this->modelManager->createFieldModel($className, $fieldName, $fieldType, $mode); foreach ($this->getProviders() as $provider) { $defaultValues = array(); $metadata = $this->getFieldMetadata($className, $fieldName); if ($metadata && isset($metadata->defaultValues[$provider->getScope()])) { $defaultValues = $metadata->defaultValues[$provider->getScope()]; } $fieldId = new FieldConfigId($className, $provider->getScope(), $fieldName, $fieldType); $config = $provider->createConfig($fieldId, $defaultValues); $this->localCache->set($config->getId()->toString(), $config); } $this->eventDispatcher->dispatch(Events::NEW_FIELD_CONFIG_MODEL, new NewFieldConfigModelEvent($fieldModel, $this)); } return $fieldModel; }
/** * @param string $className * @param string $fieldName * @param string $fieldType * @param string $mode * @return FieldConfigModel */ public function createConfigFieldModel($className, $fieldName, $fieldType, $mode = ConfigModelManager::MODE_DEFAULT) { $fieldModel = $this->modelManager->findFieldModel($className, $fieldName); if (null === $fieldModel) { $fieldModel = $this->modelManager->createFieldModel($className, $fieldName, $fieldType, $mode); $metadata = $this->getFieldMetadata($className, $fieldName); foreach ($this->getProviders() as $provider) { $configId = new FieldConfigId($provider->getScope(), $className, $fieldName, $fieldType); $config = $this->createConfig($configId, $this->getFieldDefaultValues($provider, $className, $fieldName, $fieldType, $metadata)); $configKey = $this->buildConfigKey($config->getId()); // local cache $this->localCache[$configKey] = $config; // for calculate change set $this->originalConfigs[$configKey] = clone $config; } $this->eventDispatcher->dispatch(Events::NEW_FIELD_CONFIG, new FieldConfigEvent($className, $fieldName, $this)); } return $fieldModel; }
/** * @param string $className * @param string $fieldName * @param string $fieldType * @param string|null $mode * * @return FieldConfigModel */ public function createConfigFieldModel($className, $fieldName, $fieldType, $mode = null) { $fieldModel = $this->modelManager->findFieldModel($className, $fieldName); if (null === $fieldModel) { $metadata = $this->getFieldMetadata($className, $fieldName); if (!$mode) { $mode = $metadata && $metadata->mode ? $metadata->mode : ConfigModel::MODE_DEFAULT; } $fieldModel = $this->modelManager->createFieldModel($className, $fieldName, $fieldType, $mode); foreach ($this->providers as $scope => $provider) { $configKey = $scope . '.' . $className . '.' . $fieldName; $config = new Config(new FieldConfigId($scope, $className, $fieldName, $fieldType), $this->getFieldDefaultValues($scope, $className, $fieldName, $fieldType, $metadata)); $this->mergeConfigValues($config, $configKey); // put a config to a local cache $this->cache->saveConfig($config, true); // for calculate change set if (!isset($this->originalValues[$configKey])) { $this->originalValues[$configKey] = $config->getValues(); } } // put "configurable" flag to a local cache $this->cache->saveConfigurable(true, $className, $fieldName, true); // if needed, update the list of fields in a local cache $fields = $this->cache->getFields($className, true); if (null !== $fields && !isset($fields[$fieldName])) { $fields[$fieldName] = ['i' => null, 'h' => $mode === ConfigModel::MODE_HIDDEN, 't' => $fieldType]; $this->cache->saveFields($className, $fields, true); } // @todo: Should be removed together with deprecated events if ($this->hasListeners(Events::NEW_FIELD_CONFIG)) { $this->eventDispatcher->dispatch(Events::NEW_FIELD_CONFIG, new Event\FieldConfigEvent($className, $fieldName, $this)); } $this->eventDispatcher->dispatch(Events::CREATE_FIELD, new Event\FieldConfigEvent($className, $fieldName, $this)); } return $fieldModel; }
public function testCreateFieldModel() { $meta = $this->em->getClassMetadata(EntityConfigModel::ENTITY_NAME); $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $em->expects($this->any())->method('getRepository')->will($this->returnValue(new FoundEntityConfigRepository($em, $meta))); $serviceLink = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\DependencyInjection\\Utils\\ServiceLink')->disableOriginalConstructor()->getMock(); $serviceLink->expects($this->any())->method('getService')->will($this->returnValue($em)); $configModelManager = new ConfigModelManager($serviceLink); $entityModel = FoundEntityConfigRepository::getResultConfigEntity(); $result = new FieldConfigModel('test', 'string'); $result->setMode(ConfigModelManager::MODE_DEFAULT); $entityModel->addField($result); $this->assertEquals($result, $configModelManager->createFieldModel(DemoEntity::ENTITY_NAME, 'test', 'string', ConfigModelManager::MODE_DEFAULT)); }