1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\CMSBundle\Admin; |
4
|
|
|
|
5
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
6
|
|
|
|
7
|
|
|
abstract class BaseAdmin extends AbstractAdmin |
8
|
|
|
{ |
9
|
|
|
protected $realLocales; |
10
|
|
|
protected $cmsTypes; |
11
|
|
|
protected $blockTypes; |
12
|
|
|
protected $cmsEntityTypes; |
13
|
|
|
|
14
|
|
|
protected function getRealLocales() |
15
|
|
|
{ |
16
|
|
|
if (!empty($this->realLocales)) { |
17
|
|
|
return $this->realLocales; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
$container = $this->getConfigurationPool()->getContainer(); |
21
|
|
|
|
22
|
|
|
if ($container->hasParameter('lunetics_locale.allowed_locales')) { |
23
|
|
|
$locales = $container->getParameter('lunetics_locale.allowed_locales'); |
24
|
|
|
foreach ($locales as $val) { |
25
|
|
|
$this->realLocales[$val] = $val; |
26
|
|
|
} |
27
|
|
|
} else { |
28
|
|
|
$locale = $container->getParameter('default_locale'); |
29
|
|
|
$this->realLocales[$locale] = $locale; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return $this->realLocales; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function getBlockTypes() |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
if (!empty($this->blockTypes)) { |
38
|
|
|
return $this->blockTypes; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$container = $this->getConfigurationPool()->getContainer(); |
42
|
|
|
$types = $container->getParameter('alpixel_cms.blocks'); |
43
|
|
|
$this->blockTypes = $types; |
44
|
|
|
foreach ($this->blockTypes as $key => $array) { |
45
|
|
|
if ($instanceAdmin = $this->getConfigurationPool()->getAdminByClass($array['class'])) { |
|
|
|
|
46
|
|
|
$this->blockTypes[$key]['admin'] = $instanceAdmin; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this->blockTypes; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
View Code Duplication |
public function getCMSTypes() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
if (!empty($this->cmsTypes)) { |
56
|
|
|
return $this->cmsTypes; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$container = $this->getConfigurationPool()->getContainer(); |
60
|
|
|
$types = $container->getParameter('alpixel_cms.content_types'); |
61
|
|
|
$this->cmsTypes = $types; |
62
|
|
|
foreach ($this->cmsTypes as $key => $array) { |
63
|
|
|
if ($instanceAdmin = $this->getConfigurationPool()->getAdminByClass($array['class'])) { |
|
|
|
|
64
|
|
|
$this->cmsTypes[$key]['admin'] = $instanceAdmin; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $this->cmsTypes; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function getCMSEntityTypes() |
72
|
|
|
{ |
73
|
|
|
if (!empty($this->cmsEntityTypes)) { |
74
|
|
|
return $this->cmsEntityTypes; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$cmsTypes = $this->getCMSTypes(); |
78
|
|
|
$this->cmsEntityTypes = []; |
79
|
|
|
foreach ($cmsTypes as $key => $array) { |
80
|
|
|
$type = lcfirst(substr($array['class'], (strrpos($array['class'], '\\') + 1), strlen($array['class']))); |
81
|
|
|
$this->cmsEntityTypes[$type] = $array['title']; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $this->cmsEntityTypes; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function setContentTypes($contentTypes) |
88
|
|
|
{ |
89
|
|
|
$this->cmsTypes = $contentTypes; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getContentTypes() |
93
|
|
|
{ |
94
|
|
|
return $this->cmsTypes; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.