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


PHP FieldDescriptionInterface::mergeOptions方法代码示例

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


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

示例1: fixFieldDescription

 /**
  * The method defines the correct default settings for the provided FieldDescription
  *
  * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @param array $options
  * @return void
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription, array $options = array())
 {
     $fieldDescription->mergeOptions($options);
     if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
         $metadata = $admin->getModelManager()->getMetadata($admin->getClass());
         // set the default field mapping
         if (isset($metadata->fieldMappings[$fieldDescription->getName()])) {
             $fieldDescription->setFieldMapping($metadata->fieldMappings[$fieldDescription->getName()]);
         }
         // set the default association mapping
         if (isset($metadata->associationMappings[$fieldDescription->getName()])) {
             $fieldDescription->setAssociationMapping($metadata->associationMappings[$fieldDescription->getName()]);
         }
     }
     if (!$fieldDescription->getType()) {
         throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
     }
     $fieldDescription->setAdmin($admin);
     $fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'standard'));
     // fix template value for doctrine association fields
     if (!$fieldDescription->getTemplate()) {
         $fieldDescription->setTemplate(sprintf('SonataAdminBundle:CRUD:edit_%s.html.twig', $fieldDescription->getType()));
     }
     if ($fieldDescription->getType() == ClassMetadataInfo::ONE_TO_ONE) {
         $fieldDescription->setTemplate('SonataAdminBundle:CRUD:edit_orm_one_to_one.html.twig');
         $admin->attachAdminClass($fieldDescription);
     }
     if ($fieldDescription->getType() == ClassMetadataInfo::MANY_TO_ONE) {
         $fieldDescription->setTemplate('SonataAdminBundle:CRUD:edit_orm_many_to_one.html.twig');
         $admin->attachAdminClass($fieldDescription);
     }
     if ($fieldDescription->getType() == ClassMetadataInfo::MANY_TO_MANY) {
         $fieldDescription->setTemplate('SonataAdminBundle:CRUD:edit_orm_many_to_many.html.twig');
         $admin->attachAdminClass($fieldDescription);
     }
     if ($fieldDescription->getType() == ClassMetadataInfo::ONE_TO_MANY) {
         $fieldDescription->setTemplate('SonataAdminBundle:CRUD:edit_orm_one_to_many.html.twig');
         if ($fieldDescription->getOption('edit') == 'inline' && !$fieldDescription->getOption('widget_form_field')) {
             $fieldDescription->setOption('widget_form_field', 'Bundle\\Sonata\\AdminBundle\\Form\\EditableFieldGroup');
         }
         $admin->attachAdminClass($fieldDescription);
     }
     // set correct default value
     if ($fieldDescription->getType() == 'datetime') {
         $options = $fieldDescription->getOption('form_field_options', array());
         if (!isset($options['years'])) {
             $options['years'] = range(1900, 2100);
         }
         $fieldDescription->setOption('form_field', $options);
     }
 }
开发者ID:renegare,项目名称:AdminBundle,代码行数:59,代码来源:FormContractor.php


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