/** * Override the PostController->Discussion() method before render to use our view instead. * * @param PostController $sender Sending controller instance. */ public function postController_beforeDiscussionRender_handler($sender) { // Override if we are looking at the question url. if ($sender->RequestMethod == 'question') { $sender->Form->addHidden('Type', 'Question'); $sender->title(t('Ask a Question')); $sender->setData('Breadcrumbs', array(array('Name' => $sender->data('Title'), 'Url' => '/post/question'))); } }
/** * Add javascript to the post/edit discussion page so that tagging autocomplete works. * * @param PostController $Sender */ public function postController_render_before($Sender) { $Sender->addJsFile('jquery.tokeninput.js'); $Sender->addJsFile('tagging.js', 'plugins/Tagging'); $Sender->addDefinition('PluginsTaggingAdd', Gdn::session()->checkPermission('Plugins.Tagging.Add')); $Sender->addDefinition('PluginsTaggingSearchUrl', Gdn::request()->Url('plugin/tagsearch')); // Make sure that detailed tag data is available to the form. $TagModel = TagModel::instance(); $DiscussionID = val('DiscussionID', $Sender->Data['Discussion']); if ($DiscussionID) { $Tags = $TagModel->getDiscussionTags($DiscussionID, TagModel::IX_EXTENDED); $Sender->setData($Tags); } elseif (!$Sender->Request->isPostBack() && ($tagString = $Sender->Request->get('tags'))) { $tags = explodeTrim(',', $tagString); $types = array_column(TagModel::instance()->defaultTypes(), 'key'); // Look up the tags by name. $tagData = Gdn::sql()->getWhere('Tag', array('Name' => $tags, 'Type' => $types))->resultArray(); // Add any missing tags. $tagNames = array_change_key_case(array_column($tagData, 'Name', 'Name')); foreach ($tags as $tag) { $tagKey = strtolower($tag); if (!isset($tagNames[$tagKey])) { $tagData[] = array('TagID' => $tag, 'Name' => $tagKey, 'FullName' => $tag, 'Type' => ''); } } $Sender->setData('Tags', $tagData); } }