1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace KunicMarko\SonataAnnotationBundle\Admin; |
||
6 | |||
7 | use KunicMarko\SonataAnnotationBundle\Annotation\AddRoute; |
||
8 | use KunicMarko\SonataAnnotationBundle\Annotation\RemoveRoute; |
||
9 | use Sonata\AdminBundle\Admin\AbstractAdmin; |
||
10 | use Sonata\AdminBundle\Datagrid\DatagridMapper; |
||
11 | use Sonata\AdminBundle\Datagrid\ListMapper; |
||
12 | use Sonata\AdminBundle\Form\FormMapper; |
||
13 | use Sonata\AdminBundle\Route\RouteCollection; |
||
14 | use Sonata\AdminBundle\Show\ShowMapper; |
||
15 | |||
16 | /** |
||
17 | * @author Marko Kunic <[email protected]> |
||
18 | */ |
||
19 | class AnnotationAdmin extends AbstractAdmin |
||
20 | { |
||
21 | private $datagridValuesLoaded = false; |
||
22 | |||
23 | protected function configureFormFields(FormMapper $formMapper): void |
||
24 | { |
||
25 | if ($this->request->get($this->getIdParameter())) { |
||
0 ignored issues
–
show
|
|||
26 | $this->get('sonata.annotation.reader.form') |
||
27 | ->configureEditFields($this->getReflectionClass(), $formMapper); |
||
28 | return; |
||
29 | } |
||
30 | |||
31 | $this->get('sonata.annotation.reader.form') |
||
32 | ->configureCreateFields($this->getReflectionClass(), $formMapper); |
||
33 | } |
||
34 | |||
35 | protected function configureListFields(ListMapper $listMapper): void |
||
36 | { |
||
37 | $this->get('sonata.annotation.reader.list') |
||
38 | ->configureFields($this->getReflectionClass(), $listMapper); |
||
39 | } |
||
40 | |||
41 | protected function configureShowFields(ShowMapper $showMapper): void |
||
42 | { |
||
43 | $this->get('sonata.annotation.reader.show') |
||
44 | ->configureFields($this->getReflectionClass(), $showMapper); |
||
45 | } |
||
46 | |||
47 | protected function configureDatagridFilters(DatagridMapper $datagridMapper): void |
||
48 | { |
||
49 | $this->get('sonata.annotation.reader.datagrid') |
||
50 | ->configureFields($this->getReflectionClass(), $datagridMapper); |
||
51 | } |
||
52 | |||
53 | protected function configureRoutes(RouteCollection $collection): void |
||
54 | { |
||
55 | [$addRoutes, $removeRoutes] = $this->get('sonata.annotation.reader.route') |
||
56 | ->getRoutes($this->getReflectionClass()); |
||
57 | |||
58 | /** @var AddRoute $route */ |
||
59 | foreach ($addRoutes as $route) { |
||
60 | $collection->add( |
||
61 | $route->getName(), |
||
62 | $route->path ? $this->replaceIdParameterInRoutePath($route->path) : $route->getName() |
||
63 | ); |
||
64 | } |
||
65 | |||
66 | /** @var RemoveRoute $route */ |
||
67 | foreach ($removeRoutes as $route) { |
||
68 | $collection->remove($route->getName()); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | private function replaceIdParameterInRoutePath(string $path): string |
||
73 | { |
||
74 | return str_replace(AddRoute::ID_PARAMETER, $this->getRouterIdParameter(), $path); |
||
75 | } |
||
76 | |||
77 | public function configureActionButtons($action, $object = null): array |
||
78 | { |
||
79 | return $this->get('sonata.annotation.reader.action_button') |
||
80 | ->getActions( |
||
81 | $this->getReflectionClass(), |
||
82 | parent::configureActionButtons($action, $object) |
||
83 | ); |
||
84 | } |
||
85 | |||
86 | public function getDashboardActions(): array |
||
87 | { |
||
88 | return $this->get('sonata.annotation.reader.dashboard_action') |
||
89 | ->getActions( |
||
90 | $this->getReflectionClass(), |
||
91 | parent::getDashboardActions() |
||
92 | ); |
||
93 | } |
||
94 | |||
95 | public function getExportFields(): array |
||
96 | { |
||
97 | return $this->get('sonata.annotation.reader.export') |
||
98 | ->getFields($this->getReflectionClass()) ?: parent::getExportFields(); |
||
99 | } |
||
100 | |||
101 | public function getExportFormats(): array |
||
102 | { |
||
103 | return $this->get('sonata.annotation.reader.export') |
||
104 | ->getFormats($this->getReflectionClass()) ?: parent::getExportFormats(); |
||
105 | } |
||
106 | |||
107 | public function buildDatagrid(): void |
||
108 | { |
||
109 | if (!$this->datagridValuesLoaded) { |
||
110 | $this->datagridValues = $this->get('sonata.annotation.reader.datagrid_values') |
||
111 | ->getDatagridValues($this->getReflectionClass()) ?: $this->datagridValues; |
||
112 | |||
113 | $this->datagridValuesLoaded = true; |
||
114 | } |
||
115 | |||
116 | parent::buildDatagrid(); |
||
117 | } |
||
118 | |||
119 | private function get(string $service) |
||
120 | { |
||
121 | return $this->getConfigurationPool()->getContainer()->get($service); |
||
122 | } |
||
123 | |||
124 | private function getReflectionClass(): \ReflectionClass |
||
125 | { |
||
126 | return new \ReflectionClass($this->getClass()); |
||
127 | } |
||
128 | } |
||
129 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.