NodesController::admin_add PHP Method

admin_add() public method

Admin add
public admin_add ( string $typeAlias = 'node' ) : void
$typeAlias string
return void
    public function admin_add($typeAlias = 'node')
    {
        $Node = $this->{$this->modelClass};
        $type = $Node->Taxonomy->Vocabulary->Type->findByAlias($typeAlias);
        if (!isset($type['Type']['alias'])) {
            $this->Session->setFlash(__d('croogo', 'Content type does not exist.'));
            return $this->redirect(array('action' => 'create'));
        }
        if (!empty($this->request->data)) {
            if (isset($this->request->data[$Node->alias]['type'])) {
                $typeAlias = $this->request->data[$Node->alias]['type'];
                $Node->type = $typeAlias;
            }
            if ($Node->saveNode($this->request->data, $typeAlias)) {
                Croogo::dispatchEvent('Controller.Nodes.afterAdd', $this, array('data' => $this->request->data));
                $this->Session->setFlash(__d('croogo', '%s has been saved', $type['Type']['title']), 'flash', array('class' => 'success'));
                $this->Croogo->redirect(array('action' => 'edit', $Node->id));
            } else {
                $this->Session->setFlash(__d('croogo', '%s could not be saved. Please, try again.', $type['Type']['title']), 'flash', array('class' => 'error'));
            }
        } else {
            $this->Croogo->setReferer();
            $this->request->data[$Node->alias]['user_id'] = $this->Session->read('Auth.User.id');
        }
        $this->set('title_for_layout', __d('croogo', 'Create content: %s', $type['Type']['title']));
        $Node->type = $type['Type']['alias'];
        $Node->Behaviors->attach('Tree', array('scope' => array($Node->escapeField('type') => $Node->type)));
        $this->_setCommonVariables($type);
    }