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.

Category ID from plugin

How can I get the ID of the current category from the context of a plugin?

Answers

  • look and download some of the plugins that deal with categories. thats how you learn on your own.

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

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    check out Category Auto Select plugin , it might give you an idea

  • hgtonighthgtonight ∞ · New Moderator

    Plugins hook into vanilla with event handlers. Vanilla passes the object that fired the event along as a parameter when handling events.

    Dump the sender variable to see what is in there.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    you mean these funny looking things ?

    public function CategoriesController_BeforeNewDiscussionButton_Handler($Sender) {
    if($Sender->Category) {

  • I'm not really interested in learning about it, I just wanted a quick answer

  • Got it by dumping the sender variable like @hgtonight suggested. For anyone in the future who reads this, the answer is:

    $Sender->CategoryID

  • hgtonighthgtonight ∞ · New Moderator

    @SubJunk said:
    Got it by dumping the sender variable like hgtonight suggested. For ayone in the future who reads this, the answer is:

    $Sender->CategoryID

    The sending object may not have this member. Depends on the controller and event handler.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • businessdadbusinessdad Stealth contributor MVP
    edited June 2013

    @SubJunk said:
    I'm not really interested in learning about it, I just wanted a quick answer

    If I may express my opinion, this is not a very good approach, as one misses the concepts behind approaches and solutions.

    Got it by dumping the sender variable like hgtonight suggested. For anyone in the future who reads this, the answer is:
    $Sender->CategoryID

    This confirms what I just wrote above. As @hgtonight wrote, not all $Sender instances will have a CategoryID. If "it seems to work, although I don't know exactly why", it's programming by coincidence.

  • I'm a programmer myself so I know the importance of learning these things. I was also an official Vanilla 1 developer.
    The fact is that if I learned about projects whenever I wanted to do a 5-minute edit/addition to them, I would never get anything done. I have to prioritize my time and sometimes part of that is to just get a simple solution and not look back.

    Anyway sometimes people just want to accomplish a simple edit without becoming a programmer, they're just a normal person who wants a feature that doesn't exist, and to give them answers that involve learning is a great way to alienate a potentially large section of the user-base.

  • x00x00 MVP
    edited June 2013

    If you are a programmer you should have asked a different question. You should have asked with regard to context, how to achieve something.

    Not "I don't care how it works just show me where the carburettor is...."

    to give them answers that involve learning is a great way to alienate a potentially large section of the user-base.

    This is tough, just becuase someone want to do something, if you it is not possible for them to do, without bothering to at least try to understand, they should not attempt it.

    Someone might want it to start raining kittens, it doesn’t mean they are going to get their wish.

    There is a limit to the amount of bad, or inadvisable advice we can give to "help people out".

    Irresponsible webmastering, has negative consequences, not least for the webmaster themselves.

    Also as a volunteer, I have no problem with alienating people such as this. I have a certain amount of patience, if they do not, that is tough for them.

    You asked the question, and you said you don't care, so any other theoretical users are kind of theoretical.....

    grep is your friend.

  • businessdadbusinessdad Stealth contributor MVP

    @SubJunk said:
    The fact is that if I learned about projects whenever I wanted to do a 5-minute edit/addition to them, I would never get anything done. I have to prioritize my time and sometimes part of that is to just get a simple solution and not look back.

    This is precisely why "just doing it", without complete understanding, may not be the right approach, as it can backfire very easily.

    Anyway sometimes people just want to accomplish a simple edit without becoming a programmer, they're just a normal person who wants a feature that doesn't exist, and to give them answers that involve learning is a great way to alienate a potentially large section of the user-base.

    I'm a supporter of the idea that nobody should touch any code, ever, unless he plans to maintain it. Quite simply: if you touch something, you break it and you don't know what you did, you are on your own. If you didn't want to learn how to do it properly, why should I spend time figuring out what you did?

    Personally, I don't think that there is anything wrong in excluding part of the User base from coding, if such Users are not qualified to do it. Quality over quantity applies in this case, too.

  • SubJunkSubJunk ✭✭
    edited June 2013

    You guys take it all a bit too seriously for me, after all it's just a forum and 99% of users are just using it for a few friends in a gaming guild or whatever. Sure take it seriously when it's a big business thing but for a little personal project people shouldn't touch code until they will commit to maintaining it? Sounds a bit OCD or something.
    Anyway I got my answer and it's working fine so that's good, catch you guys later :)

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    I would much rather get a whole learning experience which empowers me to progress and increases my productivity though understanding .

    to give them answers that involve learning is a great way to alienate a potentially large section of the user-base.

    That would be Assuming all people or a large user-base are lazy and stupid and incapable of learning so why bother? that is cold

    If this was true then all schools would be unnecessary and out of business , soon people would forget how to learn and would regress into cavemanship and then grunts for language since people could not learn that either, just snippets of a language they picked up somewhere ...

    A quick answer is very handy when the question is clear and concise .

    $Category=$Sender->Category; or $Category=$Sender->CategoryID

  • businessdadbusinessdad Stealth contributor MVP

    @SubJunk said:
    You guys take it all a bit too seriously for me, after all it's just a forum and 99% of users are just using it for a few friends in a gaming guild or whatever. Sure take it seriously when it's a big business thing but for a little personal project people shouldn't touch code until they will commit to maintaining it? Sounds a bit OCD or something.

    It's a forum, not "just a forum". The fact that Users use it for their gaming guild or "whatever" doesn't prevent them from screaming and pulling their hair out when things go wrong (just keep an eye on this forum and you will see what I mean). Little personal projects get out of hand quite quickly.

    As for the OCD remarks: if it's worth doing something, it's worth doing it right. If it's not done right because "it was not worth learning how to do it properly", then the old "you made your bed, now lie in it" applies.

  • peregrineperegrine MVP
    edited June 2013

    He said thank you for the help, lets leave it at that.

    He was also forthright, about wanting a quick answer, and not wanting to spend time poring over the code. It's valid, it's just not what some of us would do.

    I'd much rather answer a question like this where there person said thank you, was forth right, and hgtonight solved his issue. The the continual Bonk issue or how do I install a plugin (those are the people who shouldn't be running forums until they can read documentation).

    this should be case closed.

    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 understand what you are saying but it also a bit ungrateful if someone gives some advice, to say I don't care, gimme.

    grep is your friend.

  • I went to the mall to get some new clothes but people would only offer me fabric and sewing machines, then when I said I'd rather just get some clothes they called me ungrateful.

  • Vanilla is already a usable software for free, what more you want? Not a good analogy at all.

    You when to the shop asked for free clothes, then asked them to put a design on it for free. When they explain how you can put a design on yourself, you say I don't care about learning I just want a design, give me access to the print shop.

    grep is your friend.

  • x00x00 MVP
    edited June 2013

    The irony is if you learn to debug, like the programmer you are, then many of these questions you will be able to answer yourself.

    grep is your friend.

Sign In or Register to comment.