PathInfoBuilder.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  16. */
  17. class PathInfoBuilder implements RouteBuilderInterface
  18. {
  19. /**
  20. * @var AuditManagerInterface
  21. */
  22. protected $manager;
  23. /**
  24. * @param AuditManagerInterface $manager
  25. */
  26. public function __construct(AuditManagerInterface $manager)
  27. {
  28. $this->manager = $manager;
  29. }
  30. /**
  31. * @param AdminInterface $admin
  32. * @param RouteCollection $collection
  33. */
  34. public function build(AdminInterface $admin, RouteCollection $collection)
  35. {
  36. $collection->add('list');
  37. $collection->add('create');
  38. $collection->add('batch');
  39. $collection->add('edit', $admin->getRouterIdParameter().'/edit');
  40. $collection->add('delete', $admin->getRouterIdParameter().'/delete');
  41. $collection->add('show', $admin->getRouterIdParameter().'/show');
  42. $collection->add('export');
  43. if ($this->manager->hasReader($admin->getClass())) {
  44. $collection->add('history', $admin->getRouterIdParameter().'/history');
  45. $collection->add('history_view_revision', $admin->getRouterIdParameter().'/history/{revision}/view');
  46. $collection->add('history_compare_revisions', $admin->getRouterIdParameter().'/history/{base_revision}/{compare_revision}/compare');
  47. }
  48. if ($admin->isAclEnabled()) {
  49. $collection->add('acl', $admin->getRouterIdParameter().'/acl');
  50. }
  51. // an admin can have only one level of nested child
  52. if ($admin->getParent()) {
  53. return;
  54. }
  55. // add children urls
  56. foreach ($admin->getChildren() as $children) {
  57. $collection->addCollection($children->getRoutes());
  58. }
  59. }
  60. }