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


PHP FieldDescriptionInterface::getAssociationAdmin方法代码示例

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


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

示例1: getDefaultOptions

 public function getDefaultOptions($type, \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription)
 {
     $options = array();
     $options['sonata_field_description'] = $fieldDescription;
     if (in_array($type, array('sonata_type_model', 'sonata_type_model_list', 'orangegate_type_image', 'orangegate_type_file', 'sonata_type_model_hidden', 'sonata_type_model_autocomplete'))) {
         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();
         if ($type == 'sonata_type_model_autocomplete') {
             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()));
             }
         }
     } 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' || $type == 'orangegate_type_media_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:peruginni,项目名称:orangegate4-doctrine-orm-bundle,代码行数:34,代码来源: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: defineChildFormBuilder

 /**
  * Returns the field associated to a FieldDescriptionInterface
  *   ie : build the embedded form from the related AdminInterface instance
  *
  * @throws RuntimeException
  * @param \Symfony\Component\Form\FormBuilder $formBuilder
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @param null $fieldName
  * @return FieldGroup
  */
 protected function defineChildFormBuilder(FormBuilder $formBuilder, FieldDescriptionInterface $fieldDescription, $fieldName = null)
 {
     $fieldName = $fieldName ?: $fieldDescription->getFieldName();
     $associatedAdmin = $fieldDescription->getAssociationAdmin();
     if (!$associatedAdmin) {
         throw new \RuntimeException(sprintf('inline mode for field `%s` required an Admin definition', $fieldName));
     }
     // retrieve the related object
     $childBuilder = $formBuilder->create($fieldName, 'sonata_type_admin', array('field_description' => $fieldDescription));
     $formBuilder->add($childBuilder);
     $associatedAdmin->defineFormBuilder($childBuilder);
 }
开发者ID:renegare,项目名称:AdminBundle,代码行数:22,代码来源:FormContractor.php

示例4: 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

示例5: 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

示例6: getValueFromFieldDescription

 /**
  * return the value related to FieldDescription, if the associated object does no
  * exists => a temporary one is created.
  *
  * @param object                                              $object
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  *
  * @return mixed
  */
 public function getValueFromFieldDescription($object, FieldDescriptionInterface $fieldDescription)
 {
     $value = null;
     if (!$object) {
         return $value;
     }
     try {
         $value = $fieldDescription->getValue($object);
     } catch (NoValueException $e) {
         if ($fieldDescription->getAssociationAdmin()) {
             $value = $fieldDescription->getAssociationAdmin()->getNewInstance();
         }
     }
     return $value;
 }
开发者ID:manudatta12,项目名称:POC,代码行数:24,代码来源:FormTypeFieldExtension.php

示例7: 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

示例8: getValueFromFieldDescription

 /**
  * return the value related to FieldDescription, if the associated object does no
  * exists => a temporary one is created.
  *
  * @param object                    $object
  * @param FieldDescriptionInterface $fieldDescription
  * @param array                     $params
  *
  * @throws \RuntimeException
  *
  * @return mixed
  */
 public function getValueFromFieldDescription($object, FieldDescriptionInterface $fieldDescription, array $params = array())
 {
     if (isset($params['loop']) && $object instanceof \ArrayAccess) {
         throw new \RuntimeException('remove the loop requirement');
     }
     $value = null;
     try {
         $value = $fieldDescription->getValue($object);
     } catch (NoValueException $e) {
         if ($fieldDescription->getAssociationAdmin()) {
             $value = $fieldDescription->getAssociationAdmin()->getNewInstance();
         }
     }
     return $value;
 }
开发者ID:andrey1s,项目名称:SonataAdminBundle,代码行数:27,代码来源:SonataAdminExtension.php

示例9: 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

示例10: getValueFromFieldDescription

 /**
  * return the value related to FieldDescription, if the associated object does no
  * exists => a temporary one is created
  *
  * @param object $object
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @param array $params
  * @return mixed
  */
 public function getValueFromFieldDescription($object, FieldDescriptionInterface $fieldDescription, array $params = array())
 {
     if (isset($params['loop']) && $object instanceof \ArrayAccess) {
         throw new \RuntimeException('remove the loop requirement');
     }
     $value = $fieldDescription->getValue($object);
     // no value defined, check if the fieldDescription point to an association
     // if so, create an empty object instance
     // fixme: not sure this is the best place to do that
     if (!$value && $fieldDescription->getAssociationAdmin()) {
         $value = $fieldDescription->getAssociationAdmin()->getNewInstance();
     }
     return $value;
 }
开发者ID:renegare,项目名称:AdminBundle,代码行数:23,代码来源:SonataAdminExtension.php

示例11: getDefaultOptions

 /**
  * {@inheritdoc}
  *
  * @throws \LogicException if a sonata_type_model field does not have a
  *                         target model configured.
  */
 public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
 {
     $options = array();
     $options['sonata_field_description'] = $fieldDescription;
     if ($type == 'doctrine_phpcr_odm_tree') {
         $options['class'] = $fieldDescription->getTargetEntity();
         $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
     }
     if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list') {
         if (!$fieldDescription->getTargetEntity()) {
             throw new \LogicException(sprintf('The field "%s" in class "%s" does not have a target model defined. ' . 'Please specify the "targetDocument" attribute in the mapping for this class.', $fieldDescription->getName(), $fieldDescription->getAdmin()->getClass()));
         }
         $options['class'] = $fieldDescription->getTargetEntity();
         $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
     } elseif ($type == 'sonata_type_admin') {
         if (!$fieldDescription->getAssociationAdmin()) {
             throw $this->getAssociationAdminException($fieldDescription);
         }
         $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
         $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));
     } elseif ($type == 'sonata_type_collection') {
         if (!$fieldDescription->getAssociationAdmin()) {
             throw $this->getAssociationAdminException($fieldDescription);
         }
         $options['type'] = 'sonata_type_admin';
         $options['modifiable'] = true;
         $options['type_options'] = array('sonata_field_description' => $fieldDescription, 'data_class' => $fieldDescription->getAssociationAdmin()->getClass());
     }
     return $options;
 }
开发者ID:hason,项目名称:SonataDoctrinePhpcrAdminBundle,代码行数:36,代码来源:FormContractor.php

示例12: 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

示例13: getDefaultOptions

 /**
  * {@inheritdoc}
  *
  * @throws \LogicException if a sonata_type_model field does not have a
  *                         target model configured.
  */
 public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescription)
 {
     $options = array();
     $options['sonata_field_description'] = $fieldDescription;
     switch ($type) {
         case 'Sonata\\DoctrinePHPCRAdminBundle\\Form\\Type\\TreeModelType':
         case 'doctrine_phpcr_odm_tree':
             $options['class'] = $fieldDescription->getTargetEntity();
             $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
             break;
         case 'Sonata\\AdminBundle\\Form\\Type\\Modeltype':
         case 'sonata_type_model':
         case 'Sonata\\AdminBundle\\Form\\Type\\ModelTypeList':
         case 'sonata_type_model_list':
             if (!$fieldDescription->getTargetEntity()) {
                 throw new \LogicException(sprintf('The field "%s" in class "%s" does not have a target model defined. Please specify the "targetDocument" attribute in the mapping for this class.', $fieldDescription->getName(), $fieldDescription->getAdmin()->getClass()));
             }
             $options['class'] = $fieldDescription->getTargetEntity();
             $options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();
             break;
         case 'Sonata\\AdminBundle\\Form\\Type\\AdminType':
         case 'sonata_type_admin':
             if (!$fieldDescription->getAssociationAdmin()) {
                 throw $this->getAssociationAdminException($fieldDescription);
             }
             $options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
             $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));
             break;
         case 'Sonata\\AdminBundle\\Form\\Type\\CollectionType':
         case 'sonata_type_collection':
             if (!$fieldDescription->getAssociationAdmin()) {
                 throw $this->getAssociationAdminException($fieldDescription);
             }
             $options['type'] = 'sonata_type_admin';
             $options['modifiable'] = true;
             $options['type_options'] = array('sonata_field_description' => $fieldDescription, 'data_class' => $fieldDescription->getAssociationAdmin()->getClass());
             break;
     }
     return $options;
 }
开发者ID:jmontoyaa,项目名称:SonataDoctrinePhpcrAdminBundle,代码行数:46,代码来源:FormContractor.php


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