QueryStringBuilder.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project 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. namespace Sonata\AdminBundle\Route;
  11. use Sonata\AdminBundle\Admin\AdminInterface;
  12. use Sonata\AdminBundle\Builder\RouteBuilderInterface;
  13. use Sonata\AdminBundle\Model\AuditManagerInterface;
  14. /**
  15. * Class QueryStringBuilder.
  16. *
  17. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  18. */
  19. class QueryStringBuilder implements RouteBuilderInterface
  20. {
  21. /**
  22. * @var AuditManagerInterface
  23. */
  24. protected $manager;
  25. /**
  26. * @param AuditManagerInterface $manager
  27. */
  28. public function __construct(AuditManagerInterface $manager)
  29. {
  30. $this->manager = $manager;
  31. }
  32. /**
  33. * @param AdminInterface $admin
  34. * @param RouteCollection $collection
  35. */
  36. public function build(AdminInterface $admin, RouteCollection $collection)
  37. {
  38. $collection->add('list');
  39. $collection->add('create');
  40. $collection->add('batch');
  41. $collection->add('edit');
  42. $collection->add('delete');
  43. $collection->add('show');
  44. $collection->add('export');
  45. if ($this->manager->hasReader($admin->getClass())) {
  46. $collection->add('history', '/audit-history');
  47. $collection->add('history_view_revision', '/audit-history-view');
  48. $collection->add('history_compare_revisions', '/audit-history-compare');
  49. }
  50. if ($admin->isAclEnabled()) {
  51. $collection->add('acl', $admin->getRouterIdParameter().'/acl');
  52. }
  53. // an admin can have only one level of nested child
  54. if ($admin->getParent()) {
  55. return;
  56. }
  57. // add children urls
  58. foreach ($admin->getChildren() as $children) {
  59. $collection->addCollection($children->getRoutes());
  60. }
  61. }
  62. }