Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

Adding a notifications menu item

I like how the profile page displays a "notifications" link on the left-side menu bar. If possible, I'd like to include that link on the left-side menu bar on all pages.

I'm using bittersweet theme. When I look in bittersweet's master.default.tpl file, I see the code {asset name="Panel"} that I believe controls the side menu; however, I'm not sure where to go from here to find the necessary HTML to adjust.

Thanks for pointing me in the right direction, once again.

Comments

  • peregrineperegrine MVP
    edited October 2015

    next time post an image detaling what you would like to do.
    my guess is this.

    do you know the basics of writing a plugin?

    if not see the docs and the wiki.

    here is a function (it might have things you want) change as you wish).
    to experiment with.

    public function Base_AfterDiscussionFilters_Handler($Sender) {
    
        // show notifications link for logged in users in Discussion Filter Menu.
        if (Gdn::Session()->UserID > 0) {
        echo '<li class="Notifications">' .
                Anchor(Sprite('SpNotifications') . ' ' . T('Notifications link'),
                  '/profile/notifications',"myclassnote") . '</li>';
      }
    }
    

    future questions regarding this - you can search forum :)

    then answer is probably there.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I don't know the basics of writing a plugin. I am currently looking at some of the docs here: http://docs.vanillaforums.com/developers/plugins/ to try to get more familiar with them.

    In what file should the above function be placed?

    Thank you for your help.

  • peregrineperegrine MVP
    edited October 2015

    yes read the docs.

    In what file should the above function be placed?

    either default.php or the name of the file you based your plugin class on.

    there is a pattern look at a few plugins.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I believe I found another possible option, but I'm not sure it's the best thing to do. Is there a reason why a plugin would be a better (or maybe safer) choice than changing applications/vanilla/views/modules/discussionfilter.php to include the link you provided?

  • peregrineperegrine MVP
    edited October 2015

    I'm giving up on you! you ignore advice.

    Haven't you read any discussions that say

    Don't Modify the Core!

    you have everything you need for a plugin.

    http://docs.vanillaforums.com/developers/plugins

    read the quickstart and the wiki.

    and make an attempt to write the plugin.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I'm not sure what constitutes the core, but there's a good chance I've modified it already.

    I'd love to develop the plugin. I guess that way other people can use it as well.

  • peregrineperegrine MVP
    edited October 2015

    I'd love to develop the plugin. I guess that way other people can use it as well.

    all you need to do is wrap the code I gave you into a plugin (you need the plugin info array
    put it in a folder with the same name as plugin and use default.php (or class.nameofyourplugin.plugin.php) for the name of the file.

    its quite simple if you spend a bit of time.

    I'm not sure what constitutes the core,

    anything that came with the vanilla download.

    http://vanillaforums.org/addon/vanilla-core

    since it will get overwritten when you try to update vanilla and you go down a path you wish never went.

    that is why some people still use 8 year old vanilla 1 :) - because they programmed themselves into a corner by modifying the core.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited October 2015

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • You're right, that ended up not being so painful:

    <?php if (!defined('APPLICATION')) exit();
    
    /**
     * Notifications Menu
     */
    
    $PluginInfo['NotificationsMenu'] = array(
        'Name' => 'NotificationsMenu',
        'Description' => 'Adds the notifications link next on the left sidebar menu.',
        'Version' => '1.0',
        'MobileFriendly' => TRUE,
        'RequiredApplications' => array('Vanilla' => '2.1.11'),
        'RequiredTheme' => FALSE,
        'RequiredPlugins' => FALSE,
    );
    
    class NotificationsMenuPlugin extends Gdn_Plugin {
    
        public function Base_AfterDiscussionFilters_Handler($Sender) {
            // show notifications link for logged in users in Discussion Filter Menu.
            if (Gdn::Session()->UserID > 0) {
                $CountNotifications = Gdn::Session()->User->CountNotifications;
                $NumNotifications = T('Notifications');
                $NumNotifications .= FilterCountString($CountNotifications);
                echo '<li class="Notifications">' . Anchor(Sprite('SpNotifications') . ' ' . $NumNotifications, '/profile/notifications',"myclassnote") . '</li>';
            }
        }
    }
    

    I was wondering how I might place this link below the "Activity" link in the side menu instead of at the very bottom?

    I think the hard part about doing it this way versus working with the core is the need to figure out where I can learn what kind of "Base_AfterDiscussionFilters_Handler" options are available.

  • peregrineperegrine MVP
    edited October 2015

    @gratiafide said : options

    there is a Before or After option as far as event.

    another option - overriding a view in a cloned theme. if link position is critical and you don't want to move it with jquery.

    overriding view and cloning themes is discussed in the forum - just a search away.
    see tutorials category as well.

    be careful about outdated and stale views when you upgrade vanilla to new versions, what you copied and overrode - may be out of date after upgrade.

    next time you want something post a marked up image of exactly what you want with stringent specs. (e.g. link position above activity - lol).

    someone else will have to field future questions.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    You can user the eventi plugin (it has some bugs, but is still helpful) to get an impression what handlers are available.

    You can also do a full text search in the source code for FireEvent(). Where ever you find that, you can influence what is happening. Simplified, they will be either in controllers or models. If you found some fireEvent in the discussion controller you can use DiscussionController_TheEventYouFound_Handler($Sender, $Args) {}. $Sender is the DiscussionController. Just try decho($Sender->ControllerName);! The decho() function shows its output only to admins. Before the FireEvent you'll see some code like EventArguments['Something'] = 1234;. In your function you can access those arguments with $Args['Something']

    You have not used ...controller or ...model, but base_... This will be called for every page.

    Hope that gave you a small help to understand what you did ;)

    gratiafide
Sign In or Register to comment.