当前位置: 首页>>代码示例>>PHP>>正文


PHP ExtendHelper::getReverseRelationType方法代码示例

本文整理汇总了PHP中Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper::getReverseRelationType方法的典型用法代码示例。如果您正苦于以下问题:PHP ExtendHelper::getReverseRelationType方法的具体用法?PHP ExtendHelper::getReverseRelationType怎么用?PHP ExtendHelper::getReverseRelationType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper的用法示例。


在下文中一共展示了ExtendHelper::getReverseRelationType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createSelfRelation

 /**
  * @param ConfigInterface $fieldConfig
  */
 protected function createSelfRelation(ConfigInterface $fieldConfig)
 {
     /** @var FieldConfigId $fieldConfigId */
     $fieldConfigId = $fieldConfig->getId();
     $targetEntityClass = $fieldConfig->get('target_entity');
     $selfFieldId = new FieldConfigId('extend', $fieldConfigId->getClassName(), $fieldConfigId->getFieldName(), $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType()));
     $selfConfig = $this->extendConfigProvider->getConfig($selfFieldId->getClassName());
     $relationKey = ExtendHelper::buildRelationKey($selfFieldId->getClassName(), $selfFieldId->getFieldName(), $selfFieldId->getFieldType(), $targetEntityClass);
     /**
      * in case of oneToMany relation
      * automatically create target field (type: manyToOne)
      */
     $targetFieldId = false;
     $owner = true;
     $targetOwner = false;
     if (in_array($selfFieldId->getFieldType(), RelationType::$toManyRelations)) {
         $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()));
     }
     $selfRelationConfig = ['assign' => false, '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') ?: [];
     $selfRelations[$relationKey] = $selfRelationConfig;
     $selfConfig->set('relation', $selfRelations);
     $this->extendConfigProvider->persist($selfConfig);
     $targetConfig = $this->extendConfigProvider->getConfig($targetEntityClass);
     $targetRelationConfig = ['assign' => false, 'field_id' => $targetFieldId, 'owner' => $targetOwner, 'target_entity' => $selfFieldId->getClassName(), 'target_field_id' => $selfFieldId];
     $targetRelations = $targetConfig->get('relation') ?: [];
     $targetRelations[$relationKey] = $targetRelationConfig;
     $targetConfig->set('relation', $targetRelations);
     $fieldConfig->set('relation_key', $relationKey);
     $this->extendConfigProvider->persist($targetConfig);
 }
开发者ID:northdakota,项目名称:platform,代码行数:43,代码来源:RelationEntityConfigDumperExtension.php

示例2: updateAction

 /**
  * @Route("/update/{id}", name="oro_entityextend_field_update", requirements={"id"="\d+"}, defaults={"id"=0})
  * Acl(
  *      id="oro_entityextend_field_update",
  *      label="oro.entity_extend.action.config_field_grid.update",
  *      type="action",
  *      group_name=""
  * )
  */
 public function updateAction(EntityConfigModel $entity)
 {
     $request = $this->getRequest();
     $fieldName = $request->getSession()->get(sprintf(self::SESSION_ID_FIELD_NAME, $entity->getId()));
     $fieldType = $request->getSession()->get(sprintf(self::SESSION_ID_FIELD_TYPE, $entity->getId()));
     if (!$fieldName || !$fieldType) {
         return $this->redirect($this->generateUrl('oro_entityextend_field_create', ['id' => $entity->getId()]));
     }
     /** @var ConfigManager $configManager */
     $configManager = $this->get('oro_entity_config.config_manager');
     $extendProvider = $configManager->getProvider('extend');
     $extendEntityConfig = $extendProvider->getConfig($entity->getClassName());
     $fieldOptions = ['extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM, 'state' => ExtendScope::STATE_NEW]];
     // check if a field type is complex, for example reverse relation or public enum
     $fieldTypeParts = explode('||', $fieldType);
     if (count($fieldTypeParts) > 1) {
         if (in_array($fieldTypeParts[0], ['enum', 'multiEnum'])) {
             // enum
             $fieldType = $fieldTypeParts[0];
             $fieldOptions['enum']['enum_code'] = $fieldTypeParts[1];
         } else {
             $firstPartItems = explode('|', $fieldTypeParts[0]);
             if (count($firstPartItems) === 4) {
                 // reverse relation
                 $fieldType = ExtendHelper::getReverseRelationType($firstPartItems[0]);
                 $relationKey = $fieldTypeParts[0];
                 $fieldOptions['extend']['relation_key'] = $relationKey;
                 $relations = $extendEntityConfig->get('relation');
                 $fieldOptions['extend']['target_entity'] = $relations[$relationKey]['target_entity'];
             }
         }
     }
     $newFieldModel = $configManager->createConfigFieldModel($entity->getClassName(), $fieldName, $fieldType);
     $this->updateFieldConfigs($configManager, $newFieldModel, $fieldOptions);
     $form = $this->createForm('oro_entity_config_type', null, ['config_model' => $newFieldModel]);
     if ($request->getMethod() == 'POST') {
         $form->submit($request);
         if ($form->isValid()) {
             //persist data inside the form
             $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('oro.entity_extend.controller.config_field.message.saved'));
             $extendEntityConfig->set('upgradeable', true);
             $configManager->persist($extendEntityConfig);
             $configManager->flush();
             return $this->get('oro_ui.router')->redirectAfterSave(['route' => 'oro_entityconfig_field_update', 'parameters' => ['id' => $newFieldModel->getId()]], ['route' => 'oro_entityconfig_view', 'parameters' => ['id' => $entity->getId()]]);
         }
     }
     /** @var ConfigProvider $entityConfigProvider */
     $entityConfigProvider = $this->get('oro_entity_config.provider.entity');
     $entityConfig = $entityConfigProvider->getConfig($entity->getClassName());
     $fieldConfig = $entityConfigProvider->getConfig($entity->getClassName(), $newFieldModel->getFieldName());
     return $this->render('OroEntityConfigBundle:Config:fieldUpdate.html.twig', ['entity_config' => $entityConfig, 'field_config' => $fieldConfig, 'field' => $newFieldModel, 'form' => $form->createView(), 'formAction' => $this->generateUrl('oro_entityextend_field_update', ['id' => $entity->getId()]), 'require_js' => $configManager->getProvider('extend')->getPropertyConfig()->getRequireJsModules()]);
 }
开发者ID:xamin123,项目名称:platform,代码行数:61,代码来源:ConfigFieldGridController.php

示例3: testGetReverseRelationType

 /**
  * @dataProvider getReverseRelationTypeProvider
  */
 public function testGetReverseRelationType($type, $expectedType)
 {
     $this->assertEquals($expectedType, ExtendHelper::getReverseRelationType($type));
 }
开发者ID:snorchel,项目名称:platform,代码行数:7,代码来源:ExtendHelperTest.php

示例4: createSelfRelation

 /**
  * @param ConfigInterface $fieldConfig
  */
 protected function createSelfRelation(ConfigInterface $fieldConfig)
 {
     $selfFieldId = $this->createFieldConfigId($fieldConfig);
     $selfIsOwnerSide = true;
     $targetFieldId = false;
     $targetEntityClass = $fieldConfig->get('target_entity');
     if (in_array($selfFieldId->getFieldType(), RelationType::$toManyRelations, true)) {
         $relationFieldName = ExtendHelper::buildToManyRelationTargetFieldName($selfFieldId->getClassName(), $selfFieldId->getFieldName());
         if ($selfFieldId->getFieldType() === RelationType::ONE_TO_MANY) {
             $selfIsOwnerSide = false;
         }
         $targetFieldId = new FieldConfigId('extend', $targetEntityClass, $relationFieldName, ExtendHelper::getReverseRelationType($selfFieldId->getFieldType()));
     }
     $relationKey = $fieldConfig->get('relation_key');
     $selfConfig = $this->getEntityConfig($selfFieldId->getClassName());
     $selfRelation = ['field_id' => $selfFieldId, 'owner' => $selfIsOwnerSide, 'target_entity' => $targetEntityClass, 'target_field_id' => $targetFieldId];
     if ($fieldConfig->has('cascade')) {
         $selfRelation['cascade'] = $fieldConfig->get('cascade');
     }
     $selfRelations = $selfConfig->get('relation', false, []);
     $selfRelations[$relationKey] = $selfRelation;
     $selfConfig->set('relation', $selfRelations);
     $this->configManager->persist($selfConfig);
     $targetConfig = $this->getEntityConfig($targetEntityClass);
     $targetRelation = ['field_id' => $targetFieldId, 'owner' => !$selfIsOwnerSide, 'target_entity' => $selfFieldId->getClassName(), 'target_field_id' => $selfFieldId];
     $targetRelations = $targetConfig->get('relation', false, []);
     $targetRelations[$relationKey] = $targetRelation;
     $targetConfig->set('relation', $targetRelations);
     $this->configManager->persist($targetConfig);
 }
开发者ID:paulstoica,项目名称:platform,代码行数:33,代码来源:RelationEntityConfigDumperExtension.php


注:本文中的Oro\Bundle\EntityExtendBundle\Tools\ExtendHelper::getReverseRelationType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。