Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
DiscussionsController_Render_Before question
Linc
Admin
@Tim, I've got this in a plugin:
It works swimmingly on the index page, but fails to work on /mine and /bookmarked.
- The code *triggers* on /mine and /bookmarked (tested with 'exit')
- The ->Prefixed value is correctly set on those pages too (echoed the value)
I'm pretty sure it's a passing-by-reference issue, but I can't figure out how the Index() and Mine() methods in the DiscussionsController are doing anything differently other than the conditions being passed to Get().
Any idea what I'm doing wrong?
public function DiscussionsController_Render_Before(&$Sender) {
foreach($Sender->Discussions as &$Discussion) {
if($Discussion->Prefixed == 1)
$Discussion->Name = C('Plugins.DiscussionPrefix.Prefix').' '.$Discussion->Name;
}
}
It works swimmingly on the index page, but fails to work on /mine and /bookmarked.
- The code *triggers* on /mine and /bookmarked (tested with 'exit')
- The ->Prefixed value is correctly set on those pages too (echoed the value)
I'm pretty sure it's a passing-by-reference issue, but I can't figure out how the Index() and Mine() methods in the DiscussionsController are doing anything differently other than the conditions being passed to Get().
Any idea what I'm doing wrong?
Tagged:
0
Comments
$Sender->EventArguments['Discussion'] = &$Discussion; ... $DiscussionName = Gdn_Format::Text($Discussion->Name);
So what we've got here is "hey, you can have the discussion as a referenced event argument, but HAHA you can't change the title because no event fires before we store it in a local variable!" o_o
If I could change the title there, I wouldn't have to use my Render_Before kludge on the entire controller (that doesn't work anyway, it seems).
Vanilla Forums COO [GitHub, Twitter, About.me]