QueryStringBuilder.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. $collection->add('history_compare_revisions', '/audit-history-compare');
  42. }
  43. if ($admin->isAclEnabled()) {
  44. $collection->add('acl', $admin->getRouterIdParameter().'/acl');
  45. }
  46. // an admin can have only one level of nested child
  47. if ($admin->getParent()) {
  48. return;
  49. }
  50. // add children urls
  51. foreach ($admin->getChildren() as $children) {
  52. $collection->addCollection($children->getRoutes());
  53. }
  54. }
  55. }