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


PHP FieldDescriptionInterface::setTemplate方法代碼示例

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


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

示例1: fixFieldDescription

 /**
  * {@inheritdoc}
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     if (null === $fieldDescription->getTemplate()) {
         $fieldDescription->setTemplate('YnloAdminBundle::CRUD/list__details.html.twig');
     }
     if (null === $fieldDescription->getType()) {
         $fieldDescription->setType('_details');
     }
     if (null === $fieldDescription->getOption('name')) {
         $fieldDescription->setOption('name', 'Details');
     }
     if (null === $fieldDescription->getOption('header_style')) {
         $fieldDescription->setOption('header_style', 'width:20px');
     }
     if (null === $fieldDescription->getOption('details_template')) {
         throw new \LogicException('The option "details_template" is required');
     }
     //encode the template
     $template = base64_encode($fieldDescription->getOption('details_template'));
     $fieldDescription->setOption('details_template_encoded', $template);
     if (null === $fieldDescription->getOption('ajax')) {
         $fieldDescription->setOption('ajax', false);
     }
     if (null === $fieldDescription->getOption('code')) {
         $fieldDescription->setOption('code', '_details');
     }
     //hide default label
     if ($fieldDescription->getOption('label') == '_details' || $fieldDescription->getOption('label') == 'Details') {
         $fieldDescription->setOption('label', ' ');
     }
 }
開發者ID:ynloultratech,項目名稱:framework,代碼行數:34,代碼來源:ListDetailsFieldBuilder.php

示例2: buildActionFieldDescription

 /**
  * {@inheritdoc}
  */
 public function buildActionFieldDescription(FieldDescriptionInterface $fieldDescription)
 {
     if (null === $fieldDescription->getTemplate()) {
         $fieldDescription->setTemplate('NetworkingInitCmsBundle:CRUD:list__action.html.twig');
     }
     if (null === $fieldDescription->getType()) {
         $fieldDescription->setType('action');
     }
     if (null === $fieldDescription->getOption('name')) {
         $fieldDescription->setOption('name', 'Action');
     }
     if (null === $fieldDescription->getOption('code')) {
         $fieldDescription->setOption('code', 'Action');
     }
     if (null !== $fieldDescription->getOption('actions')) {
         $actions = $fieldDescription->getOption('actions');
         foreach ($actions as $k => $action) {
             if (!isset($action['template'])) {
                 $actions[$k]['template'] = sprintf('NetworkingInitCmsBundle:CRUD:list__action_%s.html.twig', $k);
             }
         }
         $fieldDescription->setOption('actions', $actions);
     }
     return $fieldDescription;
 }
開發者ID:rapemer,項目名稱:init-cms-bundle,代碼行數:28,代碼來源:ListBuilder.php

示例3: fixFieldDescription

 /**
  * The method defines the correct default settings for the provided FieldDescription
  *
  * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @return void
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     $fieldDescription->setAdmin($admin);
     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->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
     $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
     if (!$fieldDescription->getTemplate()) {
         $fieldDescription->setTemplate(sprintf('SonataAdminBundle:CRUD:show_%s.html.twig', $fieldDescription->getType()));
         if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_ONE) {
             $fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_many_to_one.html.twig');
         }
         if ($fieldDescription->getMappingType() == ClassMetadata::ONE_TO_ONE) {
             $fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_one_to_one.html.twig');
         }
         if ($fieldDescription->getMappingType() == ClassMetadata::ONE_TO_MANY) {
             $fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_one_to_many.html.twig');
         }
         if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_MANY) {
             $fieldDescription->setTemplate('SonataAdminBundle:CRUD:show_orm_many_to_many.html.twig');
         }
     }
     if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_ONE) {
         $admin->attachAdminClass($fieldDescription);
     }
     if ($fieldDescription->getMappingType() == ClassMetadata::ONE_TO_ONE) {
         $admin->attachAdminClass($fieldDescription);
     }
     if ($fieldDescription->getMappingType() == ClassMetadata::ONE_TO_MANY) {
         $admin->attachAdminClass($fieldDescription);
     }
     if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_MANY) {
         $admin->attachAdminClass($fieldDescription);
     }
 }
開發者ID:nzzdev,項目名稱:SonataDoctrinePhpcrAdminBundle,代碼行數:54,代碼來源:ShowBuilder.php

示例4: fixFieldDescription

 /**
  * {@inheritdoc}
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     if (null === $fieldDescription->getTemplate()) {
         $fieldDescription->setTemplate('SonataAdminBundle:CRUD:list__action.html.twig');
     }
     if (null === $fieldDescription->getType()) {
         $fieldDescription->setType('action');
     }
     if (null === $fieldDescription->getOption('name')) {
         $fieldDescription->setOption('name', 'Action');
     }
     if (null === $fieldDescription->getOption('code')) {
         $fieldDescription->setOption('code', 'Action');
     }
     if (null === $fieldDescription->getOption('header_style') && $fieldDescription->getOption('dropdown')) {
         $fieldDescription->setOption('header_style', 'width:40px');
     }
     if (null !== $fieldDescription->getOption('actions')) {
         $actions = $fieldDescription->getOption('actions');
         foreach ($actions as $k => &$action) {
             //only set the template if really exists
             //set to default any template that not exists
             if (!isset($action['template'])) {
                 if ($fieldDescription->getOption('dropdown')) {
                     $template = sprintf('SonataAdminBundle:CRUD:list__action_dropdown_%s.html.twig', $k);
                 } else {
                     $template = sprintf('SonataAdminBundle:CRUD:list__action_%s.html.twig', $k);
                 }
                 try {
                     $this->twig->loadTemplate($template);
                 } catch (\Twig_Error_Loader $e) {
                     if ($fieldDescription->getOption('dropdown')) {
                         $template = 'YnloAdminBundle::CRUD/list__action_dropdown_default.html.twig';
                     } else {
                         $template = 'YnloAdminBundle::CRUD/list__action_default.html.twig';
                     }
                 }
                 $action['template'] = $template;
             }
             //set default role
             if (!isset($action['role'])) {
                 $role = strtoupper($k);
                 $action['role'] = $role === 'SHOW' ? 'VIEW' : $role;
             }
             //set default visibility
             if (!isset($action['visible'])) {
                 $action['visible'] = true;
             }
         }
         $fieldDescription->setOption('actions', $actions);
     }
     //hide default label
     if (in_array($fieldDescription->getOption('label'), ['_action', 'Action'])) {
         $fieldDescription->setOption('label', ' ');
     }
     return $fieldDescription;
 }
開發者ID:ynloultratech,項目名稱:framework,代碼行數:60,代碼來源:ListActionFieldBuilder.php

示例5: fixFieldDescription

 /**
  * {@inheritdoc}
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     $fieldDescription->setTemplate('YnloAdminBundle::CRUD/list_enum.html.twig');
     /** @var ModelManager $modelManager */
     $modelManager = $admin->getModelManager();
     if (null === $fieldDescription->getOption('enum_type') && $modelManager->hasMetadata($admin->getClass())) {
         $mapping = $modelManager->getMetadata($admin->getClass())->getFieldMapping($fieldDescription->getName());
         $fieldDescription->setOption('enum_type', $mapping['type']);
     }
 }
開發者ID:ynloultratech,項目名稱:framework,代碼行數:13,代碼來源:ListEnumFieldBuilder.php

示例6: fixFieldDescription

 /**
  * @throws \RuntimeException
  * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  * @param \Sonata\AdminBundle\Admin\FieldDescription $fieldDescription
  * @return void
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     // set default values
     $fieldDescription->setAdmin($admin);
     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->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
     $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
     $fieldDescription->setOption('filter_value', $fieldDescription->getOption('filter_value', null));
     $fieldDescription->setOption('filter_options', $fieldDescription->getOption('filter_options', null));
     $fieldDescription->setOption('filter_field_options', $fieldDescription->getOption('filter_field_options', null));
     $fieldDescription->setOption('name', $fieldDescription->getOption('name', $fieldDescription->getName()));
     // set the default type if none is set
     if (!$fieldDescription->getType()) {
         $fieldDescription->setType('string');
     }
     if (!$fieldDescription->getTemplate()) {
         $fieldDescription->setTemplate(sprintf('SonataAdminBundle:CRUD:filter_%s.html.twig', $fieldDescription->getType()));
         if ($fieldDescription->getType() == ClassMetadataInfo::MANY_TO_ONE) {
             $fieldDescription->setTemplate('SonataAdminBundle:CRUD:filter_many_to_one.html.twig');
         }
         if ($fieldDescription->getType() == ClassMetadataInfo::MANY_TO_MANY) {
             $fieldDescription->setTemplate('SonataAdminBundle:CRUD:filter_many_to_many.html.twig');
         }
     }
 }
開發者ID:renegare,項目名稱:AdminBundle,代碼行數:44,代碼來源:DatagridBuilder.php

示例7: fixFieldDescription

 /**
  * @param \Sonata\AdminBundle\Admin\AdminInterface            $admin
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     $fieldDescription->setAdmin($admin);
     if (!$fieldDescription->getType()) {
         throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
     }
     // define the template to use
     if (!$fieldDescription->getTemplate()) {
         $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));
     }
     // define code and label
     $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
     $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
 }
開發者ID:kosolapovvp,項目名稱:SonataPropelAdminBundle,代碼行數:18,代碼來源:ShowBuilder.php

示例8: fixFieldDescription

 /**
  * The method defines the correct default settings for the provided FieldDescription
  *
  * @param \Sonata\AdminBundle\Admin\AdminInterface            $admin
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  *
  * @return void
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     $fieldDescription->setAdmin($admin);
     if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
         list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName());
         $fieldDescription->setParentAssociationMappings($parentAssociationMappings);
         // set the default field mapping
         if (isset($metadata->fieldMappings[$lastPropertyName])) {
             $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]);
         }
         // set the default association mapping
         if (isset($metadata->associationMappings[$lastPropertyName])) {
             $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]);
         }
     }
     if (!$fieldDescription->getType()) {
         throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
     }
     $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
     $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
     if (!$fieldDescription->getTemplate()) {
         $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));
         if (!$fieldDescription->getTemplate()) {
             switch ($fieldDescription->getMappingType()) {
                 case ClassMetadataInfo::MANY_TO_ONE:
                     $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_one.html.twig');
                     break;
                 case ClassMetadataInfo::ONE_TO_ONE:
                     $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_one.html.twig');
                     break;
                 case ClassMetadataInfo::ONE_TO_MANY:
                     $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_one_to_many.html.twig');
                     break;
                 case ClassMetadataInfo::MANY_TO_MANY:
                     $fieldDescription->setTemplate('SonataDoctrineORMAdminBundle:CRUD:show_orm_many_to_many.html.twig');
                     break;
             }
         }
     }
     switch ($fieldDescription->getMappingType()) {
         case ClassMetadataInfo::MANY_TO_ONE:
         case ClassMetadataInfo::ONE_TO_ONE:
         case ClassMetadataInfo::ONE_TO_MANY:
         case ClassMetadataInfo::MANY_TO_MANY:
             $admin->attachAdminClass($fieldDescription);
             break;
     }
 }
開發者ID:LamaDelRay,項目名稱:test_symf,代碼行數:56,代碼來源:ShowBuilder.php

示例9: fixFieldDescription

 /**
  * The method defines the correct default settings for the provided FieldDescription
  *
  * @param \Sonata\AdminBundle\Admin\AdminInterface            $admin
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  *
  * @return void
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     $fieldDescription->setAdmin($admin);
     if ($admin->getModelManager()->hasMetadata($admin->getClass())) {
         list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName());
         $fieldDescription->setParentAssociationMappings($parentAssociationMappings);
         // set the default field mapping
         if (isset($metadata->fieldMappings[$lastPropertyName])) {
             $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]);
         }
         // set the default association mapping
         if (isset($metadata->associationMappings[$lastPropertyName])) {
             $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]);
         }
     }
     if (!$fieldDescription->getType()) {
         throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), get_class($admin)));
     }
     $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName()));
     $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));
     if (!$fieldDescription->getTemplate()) {
         if ($fieldDescription->getType() == 'id') {
             $fieldDescription->setType('string');
         }
         if ($fieldDescription->getType() == 'int') {
             $fieldDescription->setType('integer');
         }
         $template = $this->getTemplate($fieldDescription->getType());
         if ($template === null) {
             if ($fieldDescription->getMappingType() == ClassMetadataInfo::ONE) {
                 $template = 'SonataDoctrineMongoDBAdminBundle:CRUD:show_mongo_one.html.twig';
             } elseif ($fieldDescription->getMappingType() == ClassMetadataInfo::MANY) {
                 $template = 'SonataDoctrineMongoDBAdminBundle:CRUD:show_mongo_many.html.twig';
             }
         }
         $fieldDescription->setTemplate($template);
     }
     if (in_array($fieldDescription->getMappingType(), array(ClassMetadataInfo::ONE, ClassMetadataInfo::MANY))) {
         $admin->attachAdminClass($fieldDescription);
     }
 }
開發者ID:jdshao,項目名稱:symfony_backstage,代碼行數:49,代碼來源:ShowBuilder.php

示例10: fixFieldDescription

 /**
  * {@inheritdoc}
  */
 public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
 {
     $fieldDescription->setTemplate('YnloAdminBundle::CRUD/list_collection.html.twig');
 }
開發者ID:ynloultratech,項目名稱:framework,代碼行數:7,代碼來源:ListCollectionFieldBuilder.php

示例11: 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::setTemplate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。