Skip to content

Commit

Permalink
PostType cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmulder committed Sep 8, 2015
1 parent 1a61be1 commit 4b1e375
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Admin/PostTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function beforeFilter(Event $event)
{
$slug = lcfirst($this->request->params['type']);

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

if (!$this->type) {
throw new Exception("The PostType is not registered");
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Component/CakeAdminComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public function administrators($field = null)

public function isLoggedIn()
{
if ($this->authUser()) {
return true;
$session = $this->_Controller->request->session();
if ($session->check('Auth.CakeAdmin')) {
return (bool)$session->read('Auth.CakeAdmin');
}
return false;
}
Expand Down
29 changes: 13 additions & 16 deletions src/Controller/Component/PostTypesComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ class PostTypesComponent extends Component
]
];

/**
* Components
*
* @var array
*/
public $components = [
'CakeAdmin.ModelManager'
];

/**
* Controller
*
Expand Down Expand Up @@ -136,8 +127,8 @@ public function register($model, $options = [])
'name' => ucfirst(Inflector::slug(pluginSplit($model)[1])),
'alias' => ucfirst(Inflector::humanize(pluginSplit($model)[1])),
'aliasLc' => lcfirst(Inflector::humanize(pluginSplit($model)[1])),
'singluarAlias' => ucfirst(Inflector::singularize(Inflector::humanize(pluginSplit($model)[1]))),
'singluarAliasLc' => lcfirst(Inflector::singularize(Inflector::humanize(pluginSplit($model)[1]))),
'singluarAlias' => ucfirst(Inflector::singularize(Inflector::humanize(pluginSplit($model)[1]))),
'singluarAliasLc' => lcfirst(Inflector::singularize(Inflector::humanize(pluginSplit($model)[1]))),
'description' => null,
'actions' => [
'index' => true,
Expand All @@ -156,10 +147,10 @@ public function register($model, $options = [])
];
$options = array_merge($_defaults, $options);

if(!$options['tableColumns']) {
if (!$options['tableColumns']) {
$options['tableColumns'] = $this->_generateTableColumns($model);
}
if(!$options['formFields']) {
if (!$options['formFields']) {
$options['formFields'] = $this->_generateFormFields($model);
}

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

/**
* getOptions
* getOption
*
* Returns all options of a specific PostType.
* Return single option, or all options per PostType.
*
* @param string $name Name of the PostType.
* @param string $option String of the named option.
* @return array|bool
*/
public function getOptions($name)
public function getOption($name, $option = null)
{
$postTypes = Configure::read('CA.PostTypes');

if (array_key_exists($name, $postTypes)) {
if ($option) {
if (array_key_exists($option, $postTypes[$name])) {
return $postTypes[$name][$option];
}
}
return $postTypes[$name];
}
return false;
Expand Down

0 comments on commit 4b1e375

Please sign in to comment.