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


PHP AdminInterface::getFormBuilder方法代码示例

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


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

示例1: appendFormFieldElement

 /**
  * @param AdminInterface $admin
  * @param object $subject
  * @param string $elementId
  * @return array
  */
 public function appendFormFieldElement(AdminInterface $admin, $subject, $elementId)
 {
     // retrieve the subject
     $formBuilder = $admin->getFormBuilder();
     $form = $formBuilder->getForm();
     $form->setData($subject);
     $form->submit($admin->getRequest());
     // get the field element
     $childFormBuilder = $this->getChildFormBuilder($formBuilder, $elementId);
     // retrieve the FieldDescription
     $fieldDescription = $admin->getFormFieldDescription($childFormBuilder->getName());
     try {
         $value = $fieldDescription->getValue($form->getData());
     } catch (NoValueException $e) {
         $value = null;
     }
     // retrieve the posted data
     $data = $admin->getRequest()->get($formBuilder->getName());
     if (!isset($data[$childFormBuilder->getName()])) {
         $data[$childFormBuilder->getName()] = array();
     }
     $objectCount = count($value);
     $postCount = count($data[$childFormBuilder->getName()]);
     $fields = array_keys($fieldDescription->getAssociationAdmin()->getFormFieldDescriptions());
     // for now, not sure how to do that
     $value = array();
     foreach ($fields as $name) {
         $value[$name] = '';
     }
     // add new elements to the subject
     while ($objectCount <= $postCount) {
         // append a new instance into the object
         $this->addNewInstance($form->getData(), $fieldDescription);
         $objectCount++;
     }
     $subject->orderLayoutBlocks();
     $finalForm = $admin->getFormBuilder()->getForm();
     $finalForm->setData($subject);
     // bind the data
     $finalForm->setData($form->getData());
     return array($fieldDescription, $finalForm);
 }
开发者ID:rapemer,项目名称:init-cms-bundle,代码行数:48,代码来源:PageAdminHelper.php

示例2: appendFormFieldElement

 /**
  * Note:
  *   This code is ugly, but there is no better way of doing it.
  *   For now the append form element action used to add a new row works
  *   only for direct FieldDescription (not nested one)
  *
  * @throws \RuntimeException
  *
  * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  * @param object                                   $subject
  * @param string                                   $elementId
  *
  * @return array
  */
 public function appendFormFieldElement(AdminInterface $admin, $subject, $elementId)
 {
     // retrieve the subject
     $formBuilder = $admin->getFormBuilder();
     $form = $formBuilder->getForm();
     $form->setData($subject);
     $form->handleRequest($admin->getRequest());
     $elementId = preg_replace('#.(\\d+)#', '[$1]', implode('.', $this->generateElementId($formBuilder, substr($elementId, strpos($elementId, '_') + 1))));
     // append a new instance into the object
     $this->addNewInstance($admin, $elementId);
     // return new form with empty row
     $finalForm = $admin->getFormBuilder()->getForm();
     $finalForm->setData($subject);
     $finalForm->setData($form->getData());
     return $finalForm;
 }
开发者ID:kwuerl,项目名称:SonataAdminBundle,代码行数:30,代码来源:AdminHelper.php

示例3: appendFormFieldElement

 /**
  * Note:
  *   This code is ugly, but there is no better way of doing it.
  *   For now the append form element action used to add a new row works
  *   only for direct FieldDescription (not nested one).
  *
  * @throws \RuntimeException
  *
  * @param AdminInterface $admin
  * @param object         $subject
  * @param string         $elementId
  *
  * @return array
  */
 public function appendFormFieldElement(AdminInterface $admin, $subject, $elementId)
 {
     // retrieve the subject
     $formBuilder = $admin->getFormBuilder();
     $form = $formBuilder->getForm();
     $form->setData($subject);
     $form->handleRequest($admin->getRequest());
     // get the field element
     $childFormBuilder = $this->getChildFormBuilder($formBuilder, $elementId);
     //Child form not found (probably nested one)
     //if childFormBuilder was not found resulted in fatal error getName() method call on non object
     if (!$childFormBuilder) {
         $propertyAccessor = $this->pool->getPropertyAccessor();
         $entity = $admin->getSubject();
         $path = $this->getElementAccessPath($elementId, $entity);
         $collection = $propertyAccessor->getValue($entity, $path);
         if ($collection instanceof \Doctrine\ORM\PersistentCollection || $collection instanceof \Doctrine\ODM\MongoDB\PersistentCollection) {
             //since doctrine 2.4
             $entityClassName = $collection->getTypeClass()->getName();
         } elseif ($collection instanceof \Doctrine\Common\Collections\Collection) {
             $entityClassName = $this->getEntityClassName($admin, explode('.', preg_replace('#\\[\\d*?\\]#', '', $path)));
         } else {
             throw new \Exception('unknown collection class');
         }
         $collection->add(new $entityClassName());
         $propertyAccessor->setValue($entity, $path, $collection);
         $fieldDescription = null;
     } else {
         // retrieve the FieldDescription
         $fieldDescription = $admin->getFormFieldDescription($childFormBuilder->getName());
         try {
             $value = $fieldDescription->getValue($form->getData());
         } catch (NoValueException $e) {
             $value = null;
         }
         // retrieve the posted data
         $data = $admin->getRequest()->get($formBuilder->getName());
         if (!isset($data[$childFormBuilder->getName()])) {
             $data[$childFormBuilder->getName()] = array();
         }
         $objectCount = count($value);
         $postCount = count($data[$childFormBuilder->getName()]);
         $fields = array_keys($fieldDescription->getAssociationAdmin()->getFormFieldDescriptions());
         // for now, not sure how to do that
         $value = array();
         foreach ($fields as $name) {
             $value[$name] = '';
         }
         // add new elements to the subject
         while ($objectCount < $postCount) {
             // append a new instance into the object
             $this->addNewInstance($form->getData(), $fieldDescription);
             ++$objectCount;
         }
         $this->addNewInstance($form->getData(), $fieldDescription);
     }
     $finalForm = $admin->getFormBuilder()->getForm();
     $finalForm->setData($subject);
     // bind the data
     $finalForm->setData($form->getData());
     return array($fieldDescription, $finalForm);
 }
开发者ID:ejkun,项目名称:SonataAdminBundle,代码行数:76,代码来源:AdminHelper.php


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