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


PHP FieldDescriptionInterface::getTargetEntity方法代码示例

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


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

示例1: getDefaultOptions

 /**
  * {@inheritdoc}
  */
 public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
 {
     $options = array();
     $options['sonata_field_description'] = $fieldDescription;
     if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list' || $type == 'sonata_type_model_hidden') {
         if ($fieldDescription->getOption('edit') == 'list') {
             throw new \LogicException('The ``sonata_type_model`` type does not accept an ``edit`` option anymore, please review the UPGRADE-2.1.md file from the SonataAdminBundle');
         }
         $options['class'] = $fieldDescription->getTargetEntity();
         $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
     } elseif ($type == 'sonata_type_admin') {
         if (!$fieldDescription->getAssociationAdmin()) {
             throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
         }
         if (!in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE))) {
             throw new \RuntimeException(sprintf('You are trying to add `sonata_type_admin` field `%s` which is not One-To-One or  Many-To-One. Maybe you want `sonata_model_list` instead?', $fieldDescription->getName()));
         }
         $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
         $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));
     } elseif ($type == 'sonata_type_collection') {
         if (!$fieldDescription->getAssociationAdmin()) {
             throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
         }
         $options['type'] = 'sonata_type_admin';
         $options['modifiable'] = true;
         $options['type_options'] = array('sonata_field_description' => $fieldDescription, 'data_class' => $fieldDescription->getAssociationAdmin()->getClass());
     }
     return $options;
 }
开发者ID:serialken,项目名称:BugTracker,代码行数:32,代码来源:FormContractor.php

示例2: getDefaultOptions

 /**
  * @param string                                              $type
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  *
  * @return array
  */
 public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
 {
     $options = array('sonata_field_description' => $fieldDescription);
     if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list') {
         if ($fieldDescription->getOption('edit') == 'list') {
             throw new \LogicException('The ``sonata_type_model`` type does not accept an ``edit`` option anymore, please review the UPGRADE-2.1.md file from the SonataAdminBundle');
         }
         $options['class'] = $fieldDescription->getTargetEntity();
         $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
     } elseif ($type == 'sonata_type_admin') {
         if (!$fieldDescription->getAssociationAdmin()) {
             throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
         }
         $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
         $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));
     } elseif ($type == 'sonata_type_collection') {
         if (!$fieldDescription->getAssociationAdmin()) {
             throw new \RuntimeException(sprintf('The current field `%s` is not linked to an admin. Please create one for the target entity : `%s`', $fieldDescription->getName(), $fieldDescription->getTargetEntity()));
         }
         $options['type'] = 'sonata_type_admin';
         $options['modifiable'] = true;
         $options['type_options'] = array('sonata_field_description' => $fieldDescription, 'data_class' => $fieldDescription->getAssociationAdmin()->getClass());
     }
     return $options;
 }
开发者ID:kosolapovvp,项目名称:SonataPropelAdminBundle,代码行数:31,代码来源:FormContractor.php

示例3: getDefaultOptions

 /**
  * @param $type
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @return array
  */
 public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
 {
     $options = array();
     $options['sonata_field_description'] = $fieldDescription;
     if ($type == 'doctrine_phpcr_type_tree_model') {
         $options['class'] = $fieldDescription->getTargetEntity();
         $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
     }
     if ($type == 'sonata_type_model') {
         $options['class'] = $fieldDescription->getTargetEntity();
         $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
         switch ($fieldDescription->getMappingType()) {
             case ClassMetadata::ONE_TO_MANY:
             case ClassMetadata::MANY_TO_MANY:
                 $options['multiple'] = true;
                 $options['parent'] = 'choice';
                 break;
             case ClassMetadata::MANY_TO_ONE:
             case ClassMetadata::ONE_TO_ONE:
                 break;
         }
         if ($fieldDescription->getOption('edit') == 'list') {
             $options['parent'] = 'text';
             if (!array_key_exists('required', $options)) {
                 $options['required'] = false;
             }
         }
     } else {
         if ($type == 'sonata_type_admin') {
             // nothing here ...
             $options['edit'] = 'inline';
         } else {
             if ($type == 'sonata_type_collection') {
                 $options['type'] = 'sonata_type_admin';
                 $options['modifiable'] = true;
                 $options['type_options'] = array('sonata_field_description' => $fieldDescription, 'data_class' => $fieldDescription->getAssociationAdmin()->getClass());
             }
         }
     }
     return $options;
 }
开发者ID:richardmiller,项目名称:SonataDoctrinePhpcrAdminBundle,代码行数:46,代码来源:FormContractor.php

示例4: attachAdminClass

 /**
  * {@inheritdoc}
  */
 public function attachAdminClass(FieldDescriptionInterface $fieldDescription)
 {
     $pool = $this->getConfigurationPool();
     $adminCode = $fieldDescription->getOption('admin_code');
     if ($adminCode !== null) {
         $admin = $pool->getAdminByAdminCode($adminCode);
     } else {
         $admin = $pool->getAdminByClass($fieldDescription->getTargetEntity());
     }
     if (!$admin) {
         return;
     }
     if ($this->hasRequest()) {
         $admin->setRequest($this->getRequest());
     }
     $fieldDescription->setAssociationAdmin($admin);
 }
开发者ID:andrewtch,项目名称:SonataAdminBundle,代码行数:20,代码来源:Admin.php

示例5: attachAdminClass

    /**
     * attach an admin instance to the given FieldDescription
     *
     * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
     */
    public function attachAdminClass(FieldDescriptionInterface $fieldDescription)
    {
        $pool = $this->getConfigurationPool();

        $admin = $pool->getAdminByClass($fieldDescription->getTargetEntity());
        if (!$admin) {
            return;
        }

        $fieldDescription->setAssociationAdmin($admin);
    }
开发者ID:nibsirahsieu,项目名称:AdminBundle,代码行数:16,代码来源:Admin.php

示例6: getChoices

    /**
     * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
     * @return array
     */
    public function getChoices(FieldDescriptionInterface $fieldDescription)
    {
        $modelManager = $fieldDescription->getAdmin()->getModelManager();
        $targets = $modelManager->getEntityManager()
            ->createQueryBuilder()
            ->select('t')
            ->from($fieldDescription->getTargetEntity(), 't')
            ->getQuery()
            ->execute();

        $choices = array();
        foreach ($targets as $target) {
            // todo : puts this into a configuration option and use reflection
            foreach (array('getTitle', 'getName', '__toString') as $getter) {
                if (method_exists($target, $getter)) {
                    $choices[$modelManager->getNormalizedIdentifier($target)] = $target->$getter();
                    break;
                }
            }
        }

        return $choices;
    }
开发者ID:nibsirahsieu,项目名称:AdminBundle,代码行数:27,代码来源:DatagridBuilder.php

示例7: attachAdminClass

 /**
  * attach an admin instance to the given FieldDescription
  *
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  */
 public function attachAdminClass(FieldDescriptionInterface $fieldDescription)
 {
     $pool = $this->getConfigurationPool();
     $admin = $pool->getAdminByClass($fieldDescription->getTargetEntity());
     if (!$admin) {
         throw new \RuntimeException(sprintf('You must define an Admin class for the `%s` field (targetEntity=%s)', $fieldDescription->getFieldName(), $fieldDescription->getTargetEntity()));
     }
     $fieldDescription->setAssociationAdmin($admin);
 }
开发者ID:renegare,项目名称:AdminBundle,代码行数:14,代码来源:Admin.php

示例8: getAssociationAdminException

 /**
  * @param FieldDescriptionInterface $fieldDescription
  *
  * @return \LogicException
  */
 protected function getAssociationAdminException(FieldDescriptionInterface $fieldDescription)
 {
     $msg = sprintf('The current field `%s` is not linked to an admin. Please create one', $fieldDescription->getName());
     if (in_array($fieldDescription->getMappingType(), array(ClassMetadata::MANY_TO_ONE, ClassMetadata::MANY_TO_MANY, 'referrers'))) {
         if ($fieldDescription->getTargetEntity()) {
             $msg .= " for the target document: `{$fieldDescription->getTargetEntity()}`";
         }
         $msg .= ', specify the `targetDocument` in the Reference, or the `referringDocument` in the Referrers or use the option `admin_code` to link it.';
     } else {
         $msg .= ' and use the option `admin_code` to link it.';
     }
     return new \LogicException($msg);
 }
开发者ID:hason,项目名称:SonataDoctrinePhpcrAdminBundle,代码行数:18,代码来源:FormContractor.php

示例9: defineManyToManyField

 /**
  * @param \Symfony\Component\Form\FormBuilder $formBuilder
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @return \Symfony\Component\Form\Type\FormTypeInterface
  */
 protected function defineManyToManyField(FormBuilder $formBuilder, FieldDescriptionInterface $fieldDescription)
 {
     $type = $fieldDescription->getOption('form_field_type', 'sonata_type_model');
     $options = $fieldDescription->getOption('form_field_options', array());
     if ($type == 'sonata_type_model') {
         $options['class'] = $fieldDescription->getTargetEntity();
         $options['multiple'] = true;
         $options['field_description'] = $fieldDescription;
         $options['parent'] = 'choice';
         $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
     }
     $formBuilder->add($fieldDescription->getName(), $type, $options);
 }
开发者ID:renegare,项目名称:AdminBundle,代码行数:18,代码来源:FormContractor.php

示例10: getDefaultOptions

    /**
     * @param $type
     * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
     * @param array $options
     * @return array
     */
    public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
    {
        $options = array();
        $options['sonata_field_description'] = $fieldDescription;

        if ($type == 'sonata_type_model') {
            $options['class']         = $fieldDescription->getTargetEntity();
            $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();

            switch ($fieldDescription->getMappingType()) {
                case ClassMetadataInfo::ONE_TO_MANY:
                case ClassMetadataInfo::MANY_TO_MANY:
                    $options['multiple']            = true;
                    $options['parent']              = 'choice';
                    break;

                case ClassMetadataInfo::MANY_TO_ONE:
                case ClassMetadataInfo::ONE_TO_ONE:
                    break;
            }

        } else if ($type == 'sonata_type_admin') {

            // nothing here ...
            $options['edit'] = 'inline';

        } else if ($type == 'sonata_type_collection') {

            $options['type']         = 'sonata_type_admin';
            $options['modifiable']   = true;
            $options['type_options'] = array(
                'sonata_field_description' => $fieldDescription,
                'data_class'               => $fieldDescription->getAssociationAdmin()->getClass()
            );

        }

        return $options;
    }
开发者ID:nibsirahsieu,项目名称:AdminBundle,代码行数:45,代码来源:FormContractor.php


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