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


PHP ExtendHelper::getReversRelationType方法代码示例

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


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

示例1: updateAction

 /**
  * @Route("/update/{id}", name="oro_entityextend_field_update", requirements={"id"="\d+"}, defaults={"id"=0})
  * Acl(
  *      id="oro_entityextend_field_update",
  *      label="Update custom field",
  *      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());
     $relationValues = [];
     $relationOptions = explode('||', $fieldType);
     $relationName = $relationOptions[0];
     if (isset($relationOptions[1])) {
         $fieldName = $relationOptions[1];
     }
     $relationOptions = explode('|', $relationOptions[0]);
     /**
      * fieldType example: relation|manyToOne|testentity5_relation_7
      * check if fieldType has 3rd option [fieldName]
      */
     if (count($relationOptions) == 4) {
         $fieldType = ExtendHelper::getReversRelationType($relationOptions[0]);
         $relations = $extendEntityConfig->get('relation');
         if (isset($relations[$relationName])) {
             $relationValues['target_entity'] = $relations[$relationName]['target_entity'];
             $relationValues['relation_key'] = $relationName;
         }
     }
     $newFieldModel = $configManager->createConfigFieldModel($entity->getClassName(), $fieldName, $fieldType);
     $extendFieldConfig = $extendProvider->getConfig($entity->getClassName(), $fieldName);
     $extendFieldConfig->set('owner', ExtendManager::OWNER_CUSTOM);
     $extendFieldConfig->set('state', ExtendManager::STATE_NEW);
     $extendFieldConfig->set('extend', true);
     foreach ($relationValues as $key => $value) {
         $extendFieldConfig->set($key, $value);
     }
     $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'));
             if ($extendEntityConfig->get('state') != ExtendManager::STATE_NEW) {
                 $extendEntityConfig->set('state', ExtendManager::STATE_UPDATED);
             }
             $extendEntityConfig->set('upgradeable', true);
             $configManager->persist($extendEntityConfig);
             $configManager->flush();
             return $this->get('oro_ui.router')->actionRedirect(['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', array('id' => $entity->getId())), 'require_js' => $configManager->getProvider('extend')->getPropertyConfig()->getRequireJsModules()]);
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:69,代码来源:ConfigFieldGridController.php

示例2: createSelfRelation

 protected function createSelfRelation(Config $fieldConfig)
 {
     $selfEntityClass = $fieldConfig->getId()->getClassName();
     $targetEntityClass = $fieldConfig->get('target_entity');
     $selfFieldType = $fieldConfig->getId()->getFieldType();
     $selfFieldName = $fieldConfig->getId()->getFieldName();
     $selfConfig = $this->extendConfigProvider->getConfig($selfEntityClass);
     $relationKey = implode('|', [$selfFieldType, $selfEntityClass, $targetEntityClass, $selfFieldName]);
     $scope = 'extend';
     /**
      * in case of oneToMany relation
      * automatically create target field (type: manyToOne)
      */
     $targetFieldId = false;
     $owner = true;
     $targetOwner = false;
     if (in_array($selfFieldType, ['oneToMany', 'manyToMany'])) {
         $classNameArray = explode('\\', $selfEntityClass);
         $relationFieldName = strtolower(array_pop($classNameArray)) . '_' . $selfFieldName;
         if ($selfFieldType == 'oneToMany') {
             $owner = false;
             $targetOwner = true;
         }
         $targetFieldId = new FieldConfigId($targetEntityClass, $scope, $relationFieldName, ExtendHelper::getReversRelationType($selfFieldType));
     }
     $selfRelationConfig = ['assign' => false, 'field_id' => $fieldConfig->getId(), 'owner' => $owner, 'target_entity' => $targetEntityClass, 'target_field_id' => $targetFieldId];
     $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' => $selfEntityClass, 'target_field_id' => $fieldConfig->getId()];
     $targetRelations = $targetConfig->get('relation') ?: [];
     $targetRelations[$relationKey] = $targetRelationConfig;
     $targetConfig->set('relation', $targetRelations);
     $fieldConfig->set('relation_key', $relationKey);
     $this->extendConfigProvider->persist($targetConfig);
     //$this->extendConfigProvider->persist($fieldConfig);
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:39,代码来源:ConfigSubscriber.php


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