update.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. Update notes for early users
  2. ============================
  3. * Property definitions has been removed
  4. * ``[Form|List|Datagrid|Show]Mapper::add`` signature has been updated
  5. * ``FormMapper::addType`` does not exists anymore
  6. * ListMapper now have an ``addIdentifier`` method
  7. * internal Sonata Form Types must be set as second argument of the FormMapper
  8. Example :
  9. <?php
  10. namespace Sonata\NewsBundle\Admin;
  11. use Sonata\AdminBundle\Admin\Admin;
  12. use Sonata\AdminBundle\Form\FormMapper;
  13. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  14. use Sonata\AdminBundle\Datagrid\ListMapper;
  15. use Sonata\AdminBundle\Show\ShowMapper;
  16. use Knp\Bundle\MenuBundle\MenuItem;
  17. use Application\Sonata\NewsBundle\Entity\Comment;
  18. class PostAdmin extends Admin
  19. {
  20. protected $userManager;
  21. protected function configureShowField(ShowMapper $showMapper)
  22. {
  23. $showMapper
  24. ->add('author')
  25. ->add('enabled')
  26. ->add('title')
  27. ->add('abstract')
  28. ->add('content')
  29. ->add('tags')
  30. ;
  31. }
  32. protected function configureFormFields(FormMapper $formMapper)
  33. {
  34. $formMapper
  35. ->with('General')
  36. ->add('enabled', null, array('required' => false))
  37. ->add('author', 'sonata_type_model', array(), array('edit' => 'list'))
  38. ->add('title')
  39. ->add('abstract')
  40. ->add('content')
  41. ->end()
  42. ->with('Tags')
  43. ->add('tags', 'sonata_type_model', array('expanded' => true))
  44. ->end()
  45. ->with('Options', array('collapsed' => true))
  46. ->add('commentsCloseAt')
  47. ->add('commentsEnabled', null, array('required' => false))
  48. ->add('commentsDefaultStatus', 'choice', array('choices' => Comment::getStatusList()))
  49. ->end()
  50. ;
  51. }
  52. protected function configureListFields(ListMapper $listMapper)
  53. {
  54. $listMapper
  55. ->addIdentifier('title')
  56. ->add('author')
  57. ->add('enabled')
  58. ->add('tags')
  59. ->add('commentsEnabled')
  60. ;
  61. }
  62. protected function configureDatagridFilters(DatagridMapper $datagridMapper)
  63. {
  64. $datagridMapper
  65. ->add('title')
  66. ->add('enabled')
  67. ->add('tags', 'orm_many_to_many', array('filter_field_options' => array('expanded' => true, 'multiple' => true)))
  68. ->add('with_open_comments', 'callback', array(
  69. 'template' => 'SonataAdminBundle:CRUD:filter_callback.html.twig',
  70. 'filter_options' => array(
  71. 'filter' => array($this, 'getWithOpenCommentFilter'),
  72. 'type' => 'checkbox'
  73. ),
  74. 'filter_field_options' => array(
  75. 'required' => false
  76. )
  77. ))
  78. ;
  79. }
  80. public function getWithOpenCommentFilter($queryBuilder, $alias, $field, $value)
  81. {
  82. if (!$value) {
  83. return;
  84. }
  85. $queryBuilder->leftJoin(sprintf('%s.comments', $alias), 'c');
  86. $queryBuilder->andWhere('c.status = :status');
  87. $queryBuilder->setParameter('status', Comment::STATUS_MODERATE);
  88. }
  89. }