當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。