當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FieldDescriptionInterface::getAssociationMapping方法代碼示例

本文整理匯總了PHP中Sonata\AdminBundle\Admin\FieldDescriptionInterface::getAssociationMapping方法的典型用法代碼示例。如果您正苦於以下問題:PHP FieldDescriptionInterface::getAssociationMapping方法的具體用法?PHP FieldDescriptionInterface::getAssociationMapping怎麽用?PHP FieldDescriptionInterface::getAssociationMapping使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Sonata\AdminBundle\Admin\FieldDescriptionInterface的用法示例。


在下文中一共展示了FieldDescriptionInterface::getAssociationMapping方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: addNewInstance

 /**
  * Add a new instance to the related FieldDescriptionInterface value.
  *
  * @param object                                              $object
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  *
  * @throws \RuntimeException
  */
 public function addNewInstance($object, FieldDescriptionInterface $fieldDescription)
 {
     $instance = $fieldDescription->getAssociationAdmin()->getNewInstance();
     $mapping = $fieldDescription->getAssociationMapping();
     $method = sprintf('add%s', $this->camelize($mapping['fieldName']));
     if (!method_exists($object, $method)) {
         $method = rtrim($method, 's');
         if (!method_exists($object, $method)) {
             $method = sprintf('add%s', $this->camelize(Inflector::singularize($mapping['fieldName'])));
             if (!method_exists($object, $method)) {
                 throw new \RuntimeException(sprintf('Please add a method %s in the %s class!', $method, ClassUtils::getClass($object)));
             }
         }
     }
     $object->{$method}($instance);
 }
開發者ID:netounet,項目名稱:SonataAdminBundle,代碼行數:24,代碼來源:AdminHelper.php

示例2: addNewInstance

 /**
  * {@inheritdoc}
  */
 public function addNewInstance($object, FieldDescriptionInterface $fieldDescription)
 {
     $instance = $fieldDescription->getAssociationAdmin()->getNewInstance();
     foreach ($this->newLayoutBlockParameters as $attr => $value) {
         $method = sprintf('set%s', $this->camelize($attr));
         $instance->{$method}($value);
     }
     $mapping = $fieldDescription->getAssociationMapping();
     $method = sprintf('add%s', $this->camelize($mapping['fieldName']));
     if (!method_exists($object, $method)) {
         $method = rtrim($method, 's');
         if (!method_exists($object, $method)) {
             throw new \RuntimeException(sprintf('Please add a method %s in the %s class!', $method, get_class($object)));
         }
     }
     $object->{$method}($instance);
 }
開發者ID:rapemer,項目名稱:init-cms-bundle,代碼行數:20,代碼來源:PageAdminHelper.php

示例3: addNewInstance

    /**
     * Add a new instance to the related FieldDescriptionInterface value
     *
     * @param object $object
     * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
     * @return void
     */
    public function addNewInstance($object, FieldDescriptionInterface $fieldDescription)
    {
        $instance = $fieldDescription->getAssociationAdmin()->getNewInstance();
        $mapping  = $fieldDescription->getAssociationMapping();

        $method = sprintf('add%s', $this->camelize($mapping['fieldName']));

        $object->$method($instance);
    }
開發者ID:nibsirahsieu,項目名稱:AdminBundle,代碼行數:16,代碼來源:AdminHelper.php

示例4: addField

 /**
  * Add a new field type into the provided FormBuilder
  *
  * @param \Symfony\Component\Form\FormBuilder $formBuilder
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @return void
  */
 public function addField(FormBuilder $formBuilder, FieldDescriptionInterface $fieldDescription)
 {
     // There is a bug in the GraphWalker, so for now we always load related associations
     // for more information : https://github.com/symfony/symfony/pull/1056
     if ($formBuilder->getData() && in_array($fieldDescription->getType(), array(ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY, ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::ONE_TO_ONE))) {
         $value = $fieldDescription->getValue($formBuilder->getData());
         $infos = $fieldDescription->getAssociationMapping();
         if ($value instanceof $infos['targetEntity'] && $value instanceof \Doctrine\ORM\Proxy\Proxy) {
             $relatedId = 'get' . current($fieldDescription->getAdmin()->getModelManager()->getIdentifierFieldNames($infos['targetEntity']));
             $value->{$relatedId}();
             // force to load the lazy loading method __load in the proxy methode
         }
     }
     switch ($fieldDescription->getType()) {
         case ClassMetadataInfo::ONE_TO_MANY:
             $this->getOneToManyField($formBuilder, $fieldDescription);
             break;
         case ClassMetadataInfo::MANY_TO_MANY:
             $this->defineManyToManyField($formBuilder, $fieldDescription);
             break;
         case ClassMetadataInfo::MANY_TO_ONE:
         case ClassMetadataInfo::ONE_TO_ONE:
             $this->defineOneToOneField($formBuilder, $fieldDescription);
             break;
         default:
             list($type, $default_options) = $this->getFormTypeName($fieldDescription);
             $formBuilder->add($fieldDescription->getFieldName(), $type, array_merge($default_options, $fieldDescription->getOption('form_field_options', array())));
     }
 }
開發者ID:renegare,項目名稱:AdminBundle,代碼行數:36,代碼來源:FormContractor.php


注:本文中的Sonata\AdminBundle\Admin\FieldDescriptionInterface::getAssociationMapping方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。