/** * Edit Tag form. */ public function SettingsController_EditTag_Create($Sender) { $Sender->Permission('Garden.Settings.Manage'); $Sender->Title(T('Edit Tag')); $Sender->AddSideMenu('settings/tagging'); $TagID = GetValue(0, $Sender->RequestArgs); $TagModel = new TagModel(); $Sender->Tag = $TagModel->GetWhere(array('TagID' => $TagID))->FirstRow(); // Set the model on the form. $Sender->Form->SetModel($TagModel); // Make sure the form knows which item we are editing. $Sender->Form->AddHidden('TagID', $TagID); if (!$Sender->Form->AuthenticatedPostBack()) { $Sender->Form->SetData($Sender->Tag); } else { // Make sure the tag is valid $Tag = $Sender->Form->GetFormValue('Name'); if (!TagModel::ValidateTag($Tag)) { $Sender->Form->AddError('@' . T('ValidateTag', 'Tags cannot contain spaces.')); } // Make sure that the tag name is not already in use. if ($TagModel->GetWhere(array('TagID <>' => $TagID, 'Name' => $Tag))->NumRows() > 0) { $Sender->SetData('MergeTagVisible', TRUE); if (!$Sender->Form->GetFormValue('MergeTag')) { $Sender->Form->AddError('The specified tag name is already in use.'); } } if ($Sender->Form->Save()) { $Sender->InformMessage(T('Your changes have been saved.')); } } $Sender->Render('EditTag', '', 'plugins/Tagging'); }
/** * Add the tag input to the discussion form. * @param Gdn_Controller $Sender */ public function PostController_AfterDiscussionFormOptions_Handler($Sender) { if (in_array($Sender->RequestMethod, array('discussion', 'editdiscussion', 'question'))) { // Setup, get most popular tags $TagModel = new TagModel(); $Tags = $TagModel->GetWhere(array('Type' => NULL), 'CountDiscussions', 'desc', C('Plugins.Tagging.ShowLimit', 100))->Result(DATASET_TYPE_ARRAY); $TagsHtml = count($Tags) ? '' : T('No tags have been created yet.'); $ShowTags = array(); if (is_array($Tags)) { foreach ($Tags as $Tag) { $ShowTags[] = $Tag['Name']; } unset($Tags); asort($ShowTags); } echo '<div class="Form-Tags P">'; // Tag text box echo $Sender->Form->Label('Tags', 'Tags'); echo $Sender->Form->TextBox('Tags', array('maxlength' => 255)); // Available tags echo Wrap(Anchor(T('Show popular tags'), '#'), 'span', array('class' => 'ShowTags')); foreach ($ShowTags as $Tag) { $TagsHtml .= Anchor($Tag, '#', 'AvailableTag', array('data-name' => $Tag)) . ' '; } echo Wrap($TagsHtml, 'div', array('class' => 'Hidden AvailableTags')); echo '</div>'; } }