Ejemplo n.º 1
0
 /**
  * @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;
 }
Ejemplo n.º 2
0
 public function testFieldConfigModel()
 {
     $fieldName = 'testField';
     $fieldType = 'integer';
     $entityModel = new EntityConfigModel('Test\\TestClass');
     $fieldModel = new FieldConfigModel($fieldName, $fieldType);
     $fieldModel->setEntity($entityModel);
     $this->assertEmpty($fieldModel->getId());
     $this->assertEquals($fieldName, $fieldModel->getFieldName());
     $this->assertEquals($fieldType, $fieldModel->getType());
     $this->assertSame($entityModel, $fieldModel->getEntity());
     $fieldName1 = 'testField';
     $fieldType1 = 'integer';
     $fieldModel->setFieldName($fieldName1);
     $fieldModel->setType($fieldType1);
     $this->assertEquals($fieldName1, $fieldModel->getFieldName());
     $this->assertEquals($fieldType1, $fieldModel->getType());
 }
Ejemplo n.º 3
0
 /**
  * Checks whether a field can be restored.
  * Unessential symbols, like _ or upper case letters, in a field name are ignored.
  *
  * @param FieldConfigModel $field
  *
  * @return bool
  */
 public function canFieldBeRestored(FieldConfigModel $field)
 {
     $normalizedFieldName = $this->normalizeFieldName($field->getFieldName());
     $configs = $this->extendConfigProvider->getConfigs($field->getEntity()->getClassName(), true);
     foreach ($configs as $config) {
         /** @var FieldConfigId $configId */
         $configId = $config->getId();
         $fieldName = $configId->getFieldName();
         if ($field->getFieldName() === $fieldName) {
             // skip current field
             continue;
         }
         if ($normalizedFieldName === $this->normalizeFieldName($fieldName) && !$config->is('is_deleted') && !$config->is('state', ExtendScope::STATE_DELETE)) {
             // an active field with similar name exists
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 public function test()
 {
     $this->assertEquals('test', $this->configField->getFieldName($this->configField->setFieldName('test')));
     $this->assertEquals('string', $this->configField->getType($this->configField->setType('string')));
     $this->assertEquals('Acme\\Bundle\\DemoBundle\\Entity\\TestAccount', $this->configEntity->getClassName($this->configEntity->setClassName('Acme\\Bundle\\DemoBundle\\Entity\\TestAccount')));
     /** test ConfigField set/getEntity */
     $this->configField->setEntity($this->configEntity);
     $this->assertEquals($this->configEntity, $this->configField->getEntity());
     /** test ConfigField getOptions */
     $this->assertInstanceOf('\\Doctrine\\Common\\Collections\\ArrayCollection', $this->configField->getOptions());
     /** test ConfigEntity addField */
     $this->configEntity->addField($this->configField);
     $this->assertEquals($this->configField, $this->configEntity->getField('test'));
     /** test ConfigEntity setFields */
     $this->configEntity->setFields(array($this->configField));
     $this->assertEquals(array($this->configField), $this->configEntity->getFields());
     /** test ConfigValue */
     $this->configValue->setCode('is_extend')->setScope('extend')->setValue(true)->setField($this->configField);
     $this->assertEquals(array('code' => 'is_extend', 'scope' => 'extend', 'value' => true, 'serializable' => false), $this->configValue->toArray());
     /** test Config setValues() */
     $this->configEntity->setValues(array($this->configValue));
     $this->assertEquals($this->configValue, $this->configEntity->getValue('is_extend', 'extend'));
 }
Ejemplo n.º 5
0
 public function testFieldConfigModel()
 {
     $fieldName = 'testField';
     $fieldType = 'integer';
     $entityModel = new EntityConfigModel('Test\\TestClass');
     $fieldModel = new FieldConfigModel($fieldName, $fieldType);
     $fieldModel->setEntity($entityModel);
     $this->assertEmpty($fieldModel->getId());
     $this->assertEquals($fieldName, $fieldModel->getFieldName());
     $this->assertEquals($fieldType, $fieldModel->getType());
     $this->assertSame($entityModel, $fieldModel->getEntity());
     $fieldName1 = 'testField';
     $fieldType1 = 'integer';
     $fieldModel->setFieldName($fieldName1);
     $fieldModel->setType($fieldType1);
     $this->assertEquals($fieldName1, $fieldModel->getFieldName());
     $this->assertEquals($fieldType1, $fieldModel->getType());
     $this->assertCount(0, $fieldModel->getOptions());
     $optionSet = new OptionSet();
     $fieldModel->setOptions(new ArrayCollection([$optionSet]));
     $this->assertCount(1, $fieldModel->getOptions());
     $this->assertSame($optionSet, $fieldModel->getOptions()->first());
 }
 /**
  * @return string
  */
 public function getFieldName()
 {
     return $this->configModel->getFieldName();
 }
 /**
  * @param FieldConfigModel $entity
  * @param array $searchContext
  * @return null|FieldConfigModel
  */
 protected function findExistingEntity($entity, array $searchContext = [])
 {
     return $this->databaseHelper->findOneBy($this->entityName, ['fieldName' => $entity->getFieldName(), 'entity' => $entity->getEntity()]);
 }
 /**
  * @Route(
  *      "/unremove/{id}",
  *      name="oro_entityextend_field_unremove",
  *      requirements={"id"="\d+"},
  *      defaults={"id"=0}
  * )
  * Acl(
  *      id="oro_entityextend_field_unremove",
  *      label="UnRemove custom field",
  *      type="action",
  *      group_name=""
  * )
  */
 public function unremoveAction(FieldConfigModel $field)
 {
     if (!$field) {
         throw $this->createNotFoundException('Unable to find FieldConfigModel entity.');
     }
     $className = $field->getEntity()->getClassName();
     /** @var ExtendManager $extendManager */
     $extendManager = $this->get('oro_entity_extend.extend.extend_manager');
     /** @var ConfigManager $configManager */
     $configManager = $this->get('oro_entity_config.config_manager');
     $fieldConfig = $extendManager->getConfigProvider()->getConfig($className, $field->getFieldName());
     if (!$fieldConfig->is('owner', ExtendManager::OWNER_CUSTOM)) {
         return new Response('', Codes::HTTP_FORBIDDEN);
     }
     $fieldConfig->set('state', ExtendManager::STATE_UPDATED);
     $configManager->persist($fieldConfig);
     $entityConfig = $extendManager->getConfigProvider()->getConfig($className);
     $entityConfig->set('upgradeable', true);
     $configManager->persist($entityConfig);
     $configManager->flush();
     return new JsonResponse(array('message' => 'Item was restored', 'successful' => true), Codes::HTTP_OK);
 }
Ejemplo n.º 9
0
 /**
  * Gets config id for the given model
  *
  * @param EntityConfigModel|FieldConfigModel $model
  * @param string                             $scope
  * @return ConfigIdInterface
  */
 public function getConfigIdByModel($model, $scope)
 {
     if ($model instanceof FieldConfigModel) {
         return new FieldConfigId($scope, $model->getEntity()->getClassName(), $model->getFieldName(), $model->getType());
     } else {
         return new EntityConfigId($scope, $model->getClassName());
     }
 }
Ejemplo n.º 10
0
 /**
  * @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);
         }
     }
 }