Completed
Pull Request — master (#6194)
by Vincent
05:04
created

QueryStringBuilder::build()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 9.1288
c 0
b 0
f 0
cc 5
nc 12
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Route;
15
16
use Sonata\AdminBundle\Admin\AdminInterface;
17
use Sonata\AdminBundle\Builder\RouteBuilderInterface;
18
use Sonata\AdminBundle\Model\AuditManagerInterface;
19
20
/**
21
 * NEXT_MAJOR: remove this class.
22
 *
23
 * @final since sonata-project/admin-bundle 3.52
24
 *
25
 * @deprecated since sonata-project/admin-bundle 3.62, to be removed with 4.0
26
 *
27
 * @author Thomas Rabaix <[email protected]>
28
 */
29
class QueryStringBuilder implements RouteBuilderInterface
30
{
31
    /**
32
     * @var AuditManagerInterface
33
     */
34
    protected $manager;
35
36
    public function __construct(AuditManagerInterface $manager)
37
    {
38
        $this->manager = $manager;
39
    }
40
41
    public function build(AdminInterface $admin, RouteCollection $collection)
42
    {
43
        $collection->add('list');
44
        $collection->add('create');
45
        $collection->add('batch');
46
        $collection->add('edit');
47
        $collection->add('delete');
48
        $collection->add('show');
49
        $collection->add('export');
50
51
        if ($this->manager->hasReader($admin->getClass())) {
52
            $collection->add('history', '/audit-history');
53
            $collection->add('history_view_revision', '/audit-history-view');
54
            $collection->add('history_compare_revisions', '/audit-history-compare');
55
        }
56
57
        if ($admin->isAclEnabled()) {
58
            $collection->add('acl', sprintf('%s/acl', $admin->getRouterIdParameter()));
59
        }
60
61
        // an admin can have only one level of nested child
62
        if ($admin->isChild()) {
63
            return;
64
        }
65
66
        // add children urls
67
        foreach ($admin->getChildren() as $children) {
68
            $collection->addCollection($children->getRoutes());
69
        }
70
    }
71
}
72