Skip to content

Commit 9054a69

Browse files
committed
Removal of annotation reader, only attributes can be used now
1 parent 1d7c73b commit 9054a69

20 files changed

Lines changed: 307 additions & 473 deletions
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Networking\InitCmsBundle\Admin;
6+
7+
use Networking\InitCmsBundle\AttributeReader\SonataAdminAttributeReaderInterface;
8+
use Sonata\AdminBundle\Admin\AbstractAdmin;
9+
use Sonata\AdminBundle\Datagrid\DatagridMapper;
10+
use Sonata\AdminBundle\Datagrid\ListMapper;
11+
use Sonata\AdminBundle\Form\FormMapper;
12+
use Sonata\AdminBundle\Show\ShowMapper;
13+
14+
abstract class AbstractAttributeAdmin extends AbstractAdmin
15+
{
16+
protected SonataAdminAttributeReaderInterface $attributeReader;
17+
18+
public function __construct(
19+
SonataAdminAttributeReaderInterface $attributeReader
20+
) {
21+
$this->attributeReader = $attributeReader;
22+
23+
parent::__construct();
24+
}
25+
26+
protected function configureListFields(ListMapper $list): void
27+
{
28+
$this->attributeReader->configureListFields(
29+
$this->getClass(),
30+
$list
31+
);
32+
}
33+
34+
protected function configureFormFields(FormMapper $form): void
35+
{
36+
$this->attributeReader->configureFormFields(
37+
$this->getClass(),
38+
$form
39+
);
40+
}
41+
42+
protected function configureShowFields(ShowMapper $show): void
43+
{
44+
$this->attributeReader->configureShowFields(
45+
$this->getClass(),
46+
$show
47+
);
48+
}
49+
50+
protected function configureDatagridFilters(DatagridMapper $filter): void
51+
{
52+
$this->attributeReader->configureDatagridFilters(
53+
$this->getClass(),
54+
$filter
55+
);
56+
}
57+
}

src/Admin/AbstractSonataAdminAnnotationAdmin.php

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/Admin/BaseAdmin.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Networking\InitCmsBundle\Admin;
1313

14-
use Networking\InitCmsBundle\Reader\SonataAdminAnnotationReaderInterface;
14+
use Networking\InitCmsBundle\AttributeReader\SonataAdminAttributeReaderInterface;
1515
use Sonata\AdminBundle\Admin\AbstractAdmin;
1616
use Sonata\AdminBundle\Datagrid\DatagridInterface;
1717
use Sonata\AdminBundle\Datagrid\DatagridMapper;
@@ -27,7 +27,7 @@
2727
*/
2828
abstract class BaseAdmin extends AbstractAdmin
2929
{
30-
protected $annotationReader;
30+
protected $attributeReader;
3131

3232
/**
3333
* @var array
@@ -132,6 +132,7 @@ public function getTrackedActions(): array
132132

133133
protected function configureListFields(ListMapper $list): void
134134
{
135+
135136
$this->getSonataAnnotationReader()?->configureListFields($this->getClass(), $list);
136137
}
137138

@@ -150,17 +151,17 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
150151
$this->getSonataAnnotationReader()?->configureDatagridFilters($this->getClass(), $filter);
151152
}
152153

153-
protected function getSonataAnnotationReader(): ?SonataAdminAnnotationReaderInterface
154+
protected function getSonataAnnotationReader(): ?SonataAdminAttributeReaderInterface
154155
{
155-
return $this->annotationReader;
156+
return $this->attributeReader;
156157
}
157158

158159
/**
159160
* @return $this
160161
*/
161-
public function setSonataAnnotationReader(SonataAdminAnnotationReaderInterface $annotationReader): self
162+
public function setSonataAnnotationReader(SonataAdminAttributeReaderInterface $annotationReader): self
162163
{
163-
$this->annotationReader = $annotationReader;
164+
$this->attributeReader = $annotationReader;
164165

165166
return $this;
166167
}

src/Admin/SonataAdminAnnotationDatagridMapperTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Networking\InitCmsBundle\Admin;
66

7-
use Networking\InitCmsBundle\Reader\SonataAdminAnnotationReaderInterface;
7+
use Networking\InitCmsBundle\AttributeReader\SonataAdminAttributeReaderInterface;
88
use Sonata\AdminBundle\Datagrid\DatagridMapper;
99

1010
trait SonataAdminAnnotationDatagridMapperTrait
@@ -15,7 +15,7 @@ protected function configureDatagridFilters(DatagridMapper $datagridMapper)
1515
}
1616

1717
/**
18-
* @return SonataAdminAnnotationReaderInterface
18+
* @return SonataAdminAttributeReaderInterface
1919
*/
2020
abstract protected function getSonataAnnotationReader();
2121
}

src/Admin/SonataAdminAnnotationFormMapperTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Networking\InitCmsBundle\Admin;
66

7-
use Networking\InitCmsBundle\Reader\SonataAdminAnnotationReaderInterface;
7+
use Networking\InitCmsBundle\AttributeReader\SonataAdminAttributeReaderInterface;
88
use Sonata\AdminBundle\Form\FormMapper;
99

1010
trait SonataAdminAnnotationFormMapperTrait
@@ -17,7 +17,7 @@ protected function configureFormFields(FormMapper $formMapper)
1717
}
1818

1919
/**
20-
* @return SonataAdminAnnotationReaderInterface
20+
* @return SonataAdminAttributeReaderInterface
2121
*/
2222
abstract protected function getSonataAnnotationReader();
2323
}

src/Admin/SonataAdminAnnotationListMapperTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Networking\InitCmsBundle\Admin;
66

7-
use Networking\InitCmsBundle\Reader\SonataAdminAnnotationReaderInterface;
7+
use Networking\InitCmsBundle\AttributeReader\SonataAdminAttributeReaderInterface;
88
use Sonata\AdminBundle\Datagrid\ListMapper;
99

1010
trait SonataAdminAnnotationListMapperTrait
@@ -17,7 +17,7 @@ protected function configureListFields(ListMapper $listMapper)
1717
}
1818

1919
/**
20-
* @return SonataAdminAnnotationReaderInterface
20+
* @return SonataAdminAttributeReaderInterface
2121
*/
2222
abstract protected function getSonataAnnotationReader();
2323
}

src/Admin/SonataAdminAnnotationReaderTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
namespace Networking\InitCmsBundle\Admin;
66

7-
use Networking\InitCmsBundle\Reader\SonataAdminAnnotationReaderInterface;
7+
use Networking\InitCmsBundle\AttributeReader\SonataAdminAttributeReaderInterface;
88
use Sonata\AdminBundle\Admin\Pool;
99

1010
trait SonataAdminAnnotationReaderTrait
1111
{
1212
/**
13-
* @return SonataAdminAnnotationReaderInterface
13+
* @return SonataAdminAttributeReaderInterface
1414
*/
1515
protected function getSonataAnnotationReader()
1616
{

src/Admin/SonataAdminAnnotationShowMapperTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Networking\InitCmsBundle\Admin;
66

7-
use Networking\InitCmsBundle\Reader\SonataAdminAnnotationReaderInterface;
7+
use Networking\InitCmsBundle\AttributeReader\SonataAdminAttributeReaderInterface;
88
use Sonata\AdminBundle\Show\ShowMapper;
99

1010
trait SonataAdminAnnotationShowMapperTrait
@@ -17,7 +17,7 @@ protected function configureShowFields(ShowMapper $showMapper)
1717
}
1818

1919
/**
20-
* @return SonataAdminAnnotationReaderInterface
20+
* @return SonataAdminAttributeReaderInterface
2121
*/
2222
abstract protected function getSonataAnnotationReader();
2323
}

src/Annotation/AbstractMapper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ abstract class AbstractMapper implements AdminInterface
2121
*/
2222
public $fieldDescriptionOptions = [];
2323

24+
public function __construct(
25+
?string $name = null,
26+
?string $type = null,
27+
array $fieldDescriptionOptions = []
28+
){
29+
$this->type = $type;
30+
$this->name = $name;
31+
$this->fieldDescriptionOptions = $fieldDescriptionOptions;
32+
}
33+
2434
/**
2535
* @return null|string
2636
*/

src/Annotation/FormMapper.php

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,35 @@
1010
#[\Attribute(\Attribute::TARGET_PROPERTY)]
1111
class FormMapper extends AbstractMapper implements FormInterface
1212
{
13-
/**
14-
* @var array
15-
*/
16-
public $options = [];
13+
public array $options = [];
1714

18-
/**
19-
* @var string
20-
*/
21-
public $with = null;
15+
public ?string $with = null;
2216

23-
/**
24-
* @var array
25-
*/
26-
public $withOptions = [];
17+
public array $withOptions = [];
2718

28-
/**
29-
* @var string
30-
*/
31-
public $tab = null;
19+
public ?string $tab = null;
3220

33-
/**
34-
* @var array
35-
*/
3621
public $tabOptions = [];
3722

38-
/**
39-
* @var bool
40-
*/
4123
public $ignoreOnParent = false;
4224

4325
public function __construct(
44-
string $type,
45-
array $options = [],
26+
?string $name = null,
27+
?string $type = null,
4628
array $fieldDescriptionOptions = [],
29+
array $options = [],
4730
array $withOptions = [],
4831
bool $ignoreOnParent = false,
49-
?string $name = null,
5032
?string $with = null,
5133
?string $tab = null,
52-
){
53-
$this->type = $type;
54-
$this->fieldDescriptionOptions = $fieldDescriptionOptions;
34+
) {
5535
$this->options = $options;
5636
$this->with = $with;
5737
$this->withOptions = $withOptions;
5838
$this->tab = $tab;
5939
$this->ignoreOnParent = $ignoreOnParent;
40+
41+
parent::__construct($name, $type, $fieldDescriptionOptions);
6042
}
6143

6244
/**
@@ -81,7 +63,7 @@ public function getWithOptions()
8163
}
8264

8365
/**
84-
* @return boolean
66+
* @return bool
8567
*/
8668
public function isIgnoreOnParent()
8769
{

0 commit comments

Comments
 (0)