public function add_topic_node() { $token = \Core::make('token'); $error = \Core::make('error'); $parent = $this->getNode(); if (!$token->validate('add_topic_node')) { $error->add($token->getErrorMessage()); } $title = $_POST['treeNodeTopicName']; if (!$title) { $error->add(t('Invalid title for topic.')); } if (!is_object($parent)) { $error->add(t('Invalid parent category')); } if (!$error->has()) { $topic = Topic::add($title, $parent); $r = $topic->getTreeNodeJSON(); return new JsonResponse($r); } else { return new JsonResponse($error); } }
public function add_topic_node($treeNodeParentID) { if ($this->token->validate('add_topic_node')) { $parent = TreeNode::getByID($treeNodeParentID); $tree = $parent->getTreeObject(); $title = $_POST['treeNodeTopicName']; if (!$title) { $this->error->add(t('Invalid title for topic')); } if (!is_object($parent)) { $this->error->add(t('Invalid parent category')); } $np = new Permissions($parent); if (!$np->canAddTopicTreeNode()) { $this->error->add(t('You may not add a topic here.')); } if (!$this->error->has()) { $category = TopicTreeNode::add($title, $parent); $r = $category->getTreeNodeJSON(); Loader::helper('ajax')->sendResult($r); } } else { $this->error->add($this->token->getErrorMessage()); } if ($this->error->has()) { Loader::helper('ajax')->sendError($this->error); } }