PathInfoBuilder.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 PathInfoBuilder 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', $admin->getRouterIdParameter().'/edit');
  35. $collection->add('delete', $admin->getRouterIdParameter().'/delete');
  36. $collection->add('show', $admin->getRouterIdParameter().'/show');
  37. $collection->add('export');
  38. if ($this->manager->hasReader($admin->getClass())) {
  39. $collection->add('history', $admin->getRouterIdParameter().'/history');
  40. $collection->add('history_view_revision', $admin->getRouterIdParameter().'/history/{revision}/view');
  41. }
  42. // an admin can have only one level of nested child
  43. if ($admin->getParent()) {
  44. return;
  45. }
  46. // add children urls
  47. foreach ($admin->getChildren() as $children) {
  48. $collection->addCollection($children->getRoutes());
  49. }
  50. }
  51. }