/** * Saves a tag. */ public function actionSaveTag() { $this->requirePostRequest(); $tagId = craft()->request->getPost('tagId'); if ($tagId) { $tag = craft()->tags->getTagById($tagId, craft()->locale->id); if (!$tag) { throw new Exception(Craft::t('No tag exists with the ID “{id}”', array('id' => $tagId))); } } else { $tag = new TagModel(); } // Set the tag attributes, defaulting to the existing values for whatever is missing from the post data $tag->groupId = craft()->request->getPost('groupId', $tag->groupId); $tag->getContent()->title = craft()->request->getPost('title', $tag->title); $tag->setContentFromPost('fields'); if (craft()->tags->saveTag($tag)) { craft()->userSession->setNotice(Craft::t('Tag saved.')); $this->redirectToPostedUrl($tag); } else { craft()->userSession->setError(Craft::t('Couldn’t save tag.')); // Send the tag back to the template craft()->urlManager->setRouteVariables(array('tag' => $tag)); } }