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


PHP FieldDescriptionInterface::setParentAssociationMappings方法代码示例

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


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

示例1: fixFieldDescription

 /**
  * The method defines the correct default settings for the provided FieldDescription
  *
  * @param \Sonata\AdminBundle\Admin\AdminInterface            $admin
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  *
  * @return void
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     $fieldDescription->setAdmin($admin);
     if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
         list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName());
         $fieldDescription->setParentAssociationMappings($parentAssociationMappings);
         // set the default field mapping
         if (isset($metadata->fieldMappings[$lastPropertyName])) {
             $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]);
         }
         // set the default association mapping
         if (isset($metadata->associationMappings[$lastPropertyName])) {
             $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]);
         }
     }
     if (!$fieldDescription->getType()) {
         throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
     }
     $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
     $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
     if (!$fieldDescription->getTemplate()) {
         $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));
         if (!$fieldDescription->getTemplate()) {
             switch ($fieldDescription->getMappingType()) {
                 case ClassMetadataInfo::MANY_TO_ONE:
                     $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_one.html.twig');
                     break;
                 case ClassMetadataInfo::ONE_TO_ONE:
                     $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_one.html.twig');
                     break;
                 case ClassMetadataInfo::ONE_TO_MANY:
                     $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_many.html.twig');
                     break;
                 case ClassMetadataInfo::MANY_TO_MANY:
                     $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_many.html.twig');
                     break;
             }
         }
     }
     switch ($fieldDescription->getMappingType()) {
         case ClassMetadataInfo::MANY_TO_ONE:
         case ClassMetadataInfo::ONE_TO_ONE:
         case ClassMetadataInfo::ONE_TO_MANY:
         case ClassMetadataInfo::MANY_TO_MANY:
             $admin->attachAdminClass($fieldDescription);
             break;
     }
 }
开发者ID:LamaDelRay,项目名称:test_symf,代码行数:56,代码来源:ShowBuilder.php

示例2: fixFieldDescription

 /**
  * The method defines the correct default settings for the provided FieldDescription.
  *
  * @param \Sonata\AdminBundle\Admin\AdminInterface            $admin
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     $fieldDescription->setAdmin($admin);
     if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
         list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName());
         $fieldDescription->setParentAssociationMappings($parentAssociationMappings);
         // set the default field mapping
         if (isset($metadata->fieldMappings[$lastPropertyName])) {
             $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]);
         }
         // set the default association mapping
         if (isset($metadata->associationMappings[$lastPropertyName])) {
             $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]);
         }
     }
     if (!$fieldDescription->getType()) {
         throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
     }
     $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
     $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
     if (!$fieldDescription->getTemplate()) {
         if ($fieldDescription->getType() == 'id') {
             $fieldDescription->setType('string');
         }
         if ($fieldDescription->getType() == 'int') {
             $fieldDescription->setType('integer');
         }
         $template = $this->getTemplate($fieldDescription->getType());
         if ($template === null) {
             if ($fieldDescription->getMappingType() == ClassMetadataInfo::ONE) {
                 $template = 'SonataDoctrineMongoDBAdminBundle:CRUD:show_mongo_one.html.twig';
             } elseif ($fieldDescription->getMappingType() == ClassMetadataInfo::MANY) {
                 $template = 'SonataDoctrineMongoDBAdminBundle:CRUD:show_mongo_many.html.twig';
             }
         }
         $fieldDescription->setTemplate($template);
     }
     if (in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE, ClassMetadataInfo::MANY))) {
         $admin->attachAdminClass($fieldDescription);
     }
 }
开发者ID:kamillo1888,项目名称:SonataDoctrineMongoDBAdminBundle,代码行数:47,代码来源:ShowBuilder.php


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