Skip to content

Commit 4b1e375

Browse files
committed
PostType cleanup
1 parent 1a61be1 commit 4b1e375

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

src/Controller/Admin/PostTypesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function beforeFilter(Event $event)
5353
{
5454
$slug = lcfirst($this->request->params['type']);
5555

56-
$this->type = $this->PostTypes->getOptions($slug);
56+
$this->type = $this->PostTypes->getOption($slug);
5757

5858
if (!$this->type) {
5959
throw new Exception("The PostType is not registered");

src/Controller/Component/CakeAdminComponent.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ public function administrators($field = null)
4949

5050
public function isLoggedIn()
5151
{
52-
if ($this->authUser()) {
53-
return true;
52+
$session = $this->_Controller->request->session();
53+
if ($session->check('Auth.CakeAdmin')) {
54+
return (bool)$session->read('Auth.CakeAdmin');
5455
}
5556
return false;
5657
}

src/Controller/Component/PostTypesComponent.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ class PostTypesComponent extends Component
5050
]
5151
];
5252

53-
/**
54-
* Components
55-
*
56-
* @var array
57-
*/
58-
public $components = [
59-
'CakeAdmin.ModelManager'
60-
];
61-
6253
/**
6354
* Controller
6455
*
@@ -136,8 +127,8 @@ public function register($model, $options = [])
136127
'name' => ucfirst(Inflector::slug(pluginSplit($model)[1])),
137128
'alias' => ucfirst(Inflector::humanize(pluginSplit($model)[1])),
138129
'aliasLc' => lcfirst(Inflector::humanize(pluginSplit($model)[1])),
139-
'singluarAlias' => ucfirst(Inflector::singularize(Inflector::humanize(pluginSplit($model)[1]))),
140-
'singluarAliasLc' => lcfirst(Inflector::singularize(Inflector::humanize(pluginSplit($model)[1]))),
130+
'singluarAlias' => ucfirst(Inflector::singularize(Inflector::humanize(pluginSplit($model)[1]))),
131+
'singluarAliasLc' => lcfirst(Inflector::singularize(Inflector::humanize(pluginSplit($model)[1]))),
141132
'description' => null,
142133
'actions' => [
143134
'index' => true,
@@ -156,10 +147,10 @@ public function register($model, $options = [])
156147
];
157148
$options = array_merge($_defaults, $options);
158149

159-
if(!$options['tableColumns']) {
150+
if (!$options['tableColumns']) {
160151
$options['tableColumns'] = $this->_generateTableColumns($model);
161152
}
162-
if(!$options['formFields']) {
153+
if (!$options['formFields']) {
163154
$options['formFields'] = $this->_generateFormFields($model);
164155
}
165156

@@ -184,18 +175,24 @@ public function register($model, $options = [])
184175
}
185176

186177
/**
187-
* getOptions
178+
* getOption
188179
*
189-
* Returns all options of a specific PostType.
180+
* Return single option, or all options per PostType.
190181
*
191182
* @param string $name Name of the PostType.
183+
* @param string $option String of the named option.
192184
* @return array|bool
193185
*/
194-
public function getOptions($name)
186+
public function getOption($name, $option = null)
195187
{
196188
$postTypes = Configure::read('CA.PostTypes');
197189

198190
if (array_key_exists($name, $postTypes)) {
191+
if ($option) {
192+
if (array_key_exists($option, $postTypes[$name])) {
193+
return $postTypes[$name][$option];
194+
}
195+
}
199196
return $postTypes[$name];
200197
}
201198
return false;

0 commit comments

Comments
 (0)