/** * Populates an element model based on a query result. * * @param array $row * @return array */ public function populateElementModel($row) { return Menus_NodeModel::populateModel($row); }
/** * Saves an node. */ public function actionSaveNode() { $this->requirePostRequest(); $nodeId = craft()->request->getPost('nodeId'); if ($nodeId) { $node = craft()->menus_nodes->getNodeById($nodeId); if (!$node) { throw new Exception(Craft::t('No node exists with the ID “{id}”', array('id' => $nodeId))); } } else { $node = new Menus_NodeModel(); } // Set the node attributes, defaulting to the existing values for whatever is missing from the post data $node->menuId = craft()->request->getPost('menuId', $node->menuId); $linkedEntry = craft()->request->getPost('linkedEntryId'); $node->enabled = (bool) craft()->request->getPost('enabled', $node->enabled); if (is_array($linkedEntry)) { $node->linkedEntryId = isset($linkedEntry[0]) ? $linkedEntry[0] : null; } $node->customUrl = craft()->request->getPost('customUrl', $node->customUrl); $node->getContent()->title = craft()->request->getPost('title', $node->title); // Parent $parentId = craft()->request->getPost('parentId'); if (is_array($parentId)) { $parentId = isset($parentId[0]) ? $parentId[0] : null; } $node->newParentId = $parentId; $node->setContentFromPost('fields'); if (craft()->menus_nodes->saveNode($node)) { craft()->userSession->setNotice(Craft::t('Node saved.')); $this->redirectToPostedUrl($node); } else { craft()->userSession->setError(Craft::t('Couldn’t save node.')); // Send the node back to the template craft()->urlManager->setRouteVariables(array('node' => $node)); } }