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


PHP FieldDescriptionInterface::setType方法代码示例

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


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

示例1: addFilter

 /**
  * {@inheritdoc}
  */
 public function addFilter(DatagridInterface $datagrid, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
 {
     // Try to wrap all types to search types
     if ($type == null) {
         $guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
         $type = $guessType->getType();
         $fieldDescription->setType($type);
         $options = $guessType->getOptions();
         foreach ($options as $name => $value) {
             if (is_array($value)) {
                 $fieldDescription->setOption($name, array_merge($value, $fieldDescription->getOption($name, array())));
             } else {
                 $fieldDescription->setOption($name, $fieldDescription->getOption($name, $value));
             }
         }
     } else {
         $fieldDescription->setType($type);
     }
     $this->fixFieldDescription($admin, $fieldDescription);
     $admin->addFilterFieldDescription($fieldDescription->getName(), $fieldDescription);
     $fieldDescription->mergeOption('field_options', array('required' => false));
     $filter = $this->filterFactory->create($fieldDescription->getName(), $type, $fieldDescription->getOptions());
     if (false !== $filter->getLabel() && !$filter->getLabel()) {
         $filter->setLabel($admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'filter', 'label'));
     }
     $datagrid->addFilter($filter);
 }
开发者ID:Kertudex,项目名称:SonataAdminSearchBundle,代码行数:30,代码来源:ElasticaDatagridBuilder.php

示例2: addField

 /**
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionCollection $list
  * @param null                                                 $type
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface  $fieldDescription
  * @param \Sonata\AdminBundle\Admin\AdminInterface             $admin
  */
 public function addField(FieldDescriptionCollection $list, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
 {
     if ($type == null) {
         $guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
         $fieldDescription->setType($guessType->getType());
     } else {
         $fieldDescription->setType($type);
     }
     $this->fixFieldDescription($admin, $fieldDescription);
     $admin->addShowFieldDescription($fieldDescription->getName(), $fieldDescription);
     $list->add($fieldDescription);
 }
开发者ID:kosolapovvp,项目名称:SonataPropelAdminBundle,代码行数:18,代码来源:ShowBuilder.php

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

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

示例5: addFilter

 /**
  * @param \Sonata\AdminBundle\Datagrid\DatagridInterface      $datagrid
  * @param null                                                $type
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @param \Sonata\AdminBundle\Admin\AdminInterface            $admin
  */
 public function addFilter(DatagridInterface $datagrid, $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
 {
     if ($type == null) {
         $guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
         $type = $guessType->getType();
         $fieldDescription->setType($type);
         $options = $guessType->getOptions();
         foreach ($options as $name => $value) {
             if (is_array($value)) {
                 $fieldDescription->setOption($name, array_merge($value, $fieldDescription->getOption($name, array())));
             } else {
                 $fieldDescription->setOption($name, $fieldDescription->getOption($name, $value));
             }
         }
     } else {
         $fieldDescription->setType($type);
     }
     $this->fixFieldDescription($admin, $fieldDescription);
     $admin->addFilterFieldDescription($fieldDescription->getName(), $fieldDescription);
     $fieldDescription->mergeOption('field_options', array('required' => false));
     if ($type === 'doctrine_orm_model_autocomplete') {
         $fieldDescription->mergeOption('field_options', array('class' => $fieldDescription->getTargetEntity(), 'model_manager' => $fieldDescription->getAdmin()->getModelManager(), 'admin_code' => $admin->getCode(), 'context' => 'filter'));
     }
     $filter = $this->filterFactory->create($fieldDescription->getName(), $type, $fieldDescription->getOptions());
     if (false !== $filter->getLabel() && !$filter->getLabel()) {
         $filter->setLabel($admin->getLabelTranslatorStrategy()->getLabel($fieldDescription->getName(), 'filter', 'label'));
     }
     $datagrid->addFilter($filter);
 }
开发者ID:netounet,项目名称:SonataDoctrineORMAdminBundle,代码行数:35,代码来源:DatagridBuilder.php

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

示例7: addField

 /**
  * {@inheritDoc}
  */
 public function addField(FieldDescriptionCollection $list, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
 {
     if ($type == null) {
         $guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
         $fieldDescription->setType($guessType->getType());
     } else {
         $fieldDescription->setType($type);
     }
     $this->fixFieldDescription($admin, $fieldDescription);
     $admin->addShowFieldDescription($fieldDescription->getName(), $fieldDescription);
     switch ($fieldDescription->getMappingType()) {
         case ClassMetadata::MANY_TO_ONE:
         case ClassMetadata::MANY_TO_MANY:
             return;
         default:
             $list->add($fieldDescription);
     }
 }
开发者ID:Aaike,项目名称:SonataDoctrinePhpcrAdminBundle,代码行数:21,代码来源:ShowBuilder.php

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

示例9: addFilter

 /**
  * @param \Sonata\AdminBundle\Datagrid\DatagridInterface $datagrid
  * @param null $type
  * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
  * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  * @return \Sonata\AdminBundle\Filter\FilterInterface
  */
 public function addFilter(DatagridInterface $datagrid, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
 {
     if ($type == null) {
         $guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName());
         $type = $guessType->getType();
         $fieldDescription->setType($type);
         $options = $guessType->getOptions();
         foreach ($options as $name => $value) {
             if (is_array($value)) {
                 $fieldDescription->setOption($name, array_merge($value, $fieldDescription->getOption($name, array())));
             } else {
                 $fieldDescription->setOption($name, $fieldDescription->getOption($name, $value));
             }
         }
     } else {
         $fieldDescription->setType($type);
     }
     $this->fixFieldDescription($admin, $fieldDescription);
     $admin->addFilterFieldDescription($fieldDescription->getName(), $fieldDescription);
     $fieldDescription->mergeOption('field_options', array('required' => false));
     $filter = $this->filterFactory->create($fieldDescription->getName(), $type, $fieldDescription->getOptions());
     $datagrid->addFilter($filter);
     return $datagrid->addFilter($filter);
 }
开发者ID:helmer,项目名称:SonataAdminBundle,代码行数:31,代码来源:DatagridBuilder.php

示例10: addFilter

    /**
     * @param \Sonata\AdminBundle\Datagrid\DatagridInterface $datagrid
     * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription
     * @return bool
     */
    public function addFilter(DatagridInterface $datagrid, $type = null, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
    {
        if ($type == null) {
            $guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName());
            $fieldDescription->setType($guessType->getType());
        } else {
            $fieldDescription->setType($type);
        }

        $this->fixFieldDescription($admin, $fieldDescription);
        $admin->addFilterFieldDescription($fieldDescription->getName(), $fieldDescription);

        switch($fieldDescription->getMappingType()) {
            case ClassMetadataInfo::MANY_TO_ONE:
                $options = $fieldDescription->getOption('filter_field_options');
                $filter = new \Sonata\AdminBundle\Filter\ORM\IntegerFilter($fieldDescription);

                break;

            case ClassMetadataInfo::MANY_TO_MANY:
                $options = $fieldDescription->getOption('filter_field_options');
                $options['choices'] = $this->getChoices($fieldDescription);


                $fieldDescription->setOption('filter_field_options', $options);

                $filter = new \Sonata\AdminBundle\Filter\ORM\ChoiceFilter($fieldDescription);

                break;

            default:
                $class = $this->getFilterFieldClass($fieldDescription);
                $filter = new $class($fieldDescription);
        }

        return $datagrid->addFilter($filter);
    }
开发者ID:nibsirahsieu,项目名称:AdminBundle,代码行数:42,代码来源:DatagridBuilder.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
  *
  * @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


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