QueryStringBuilder.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Sonata package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. *
  10. */
  11. namespace Sonata\AdminBundle\Route;
  12. use Sonata\AdminBundle\Builder\RouteBuilderInterface;
  13. use Sonata\AdminBundle\Admin\AdminInterface;
  14. use Sonata\AdminBundle\Model\AuditManagerInterface;
  15. class QueryStringBuilder implements RouteBuilderInterface
  16. {
  17. protected $manager;
  18. /**
  19. * @param \Sonata\AdminBundle\Model\AuditManagerInterface $manager
  20. */
  21. public function __construct(AuditManagerInterface $manager)
  22. {
  23. $this->manager = $manager;
  24. }
  25. /**
  26. * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  27. * @param \Sonata\AdminBundle\Route\RouteCollection $collection
  28. */
  29. public function build(AdminInterface $admin, RouteCollection $collection)
  30. {
  31. $collection->add('list');
  32. $collection->add('create');
  33. $collection->add('batch');
  34. $collection->add('edit');
  35. $collection->add('delete');
  36. $collection->add('show');
  37. $collection->add('export');
  38. if ($this->manager->hasReader($admin->getClass())) {
  39. $collection->add('history', '/audit-history');
  40. $collection->add('history_view_revision', '/audit-history-view');
  41. }
  42. if ($admin->isAclEnabled()) {
  43. $collection->add('acl', $admin->getRouterIdParameter().'/acl');
  44. }
  45. // an admin can have only one level of nested child
  46. if ($admin->getParent()) {
  47. return;
  48. }
  49. // add children urls
  50. foreach ($admin->getChildren() as $children) {
  51. $collection->addCollection($children->getRoutes());
  52. }
  53. }
  54. }