QueryStringBuilder.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. class QueryStringBuilder implements RouteBuilderInterface
  15. {
  16. protected $manager;
  17. /**
  18. * @param \Sonata\AdminBundle\Model\AuditManagerInterface $manager
  19. */
  20. public function __construct(AuditManagerInterface $manager)
  21. {
  22. $this->manager = $manager;
  23. }
  24. /**
  25. * @param \Sonata\AdminBundle\Admin\AdminInterface $admin
  26. * @param \Sonata\AdminBundle\Route\RouteCollection $collection
  27. */
  28. public function build(AdminInterface $admin, RouteCollection $collection)
  29. {
  30. $collection->add('list');
  31. $collection->add('create');
  32. $collection->add('batch');
  33. $collection->add('edit');
  34. $collection->add('delete');
  35. $collection->add('show');
  36. $collection->add('export');
  37. if ($this->manager->hasReader($admin->getClass())) {
  38. $collection->add('history', '/audit-history');
  39. $collection->add('history_view_revision', '/audit-history-view');
  40. $collection->add('history_compare_revisions', '/audit-history-compare');
  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. }