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