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.
Get values from a particular plugins via fireEvent
vanillawhisky
New
Hello there,
I have a small question here.
lets say I want to use a plugins name xyz and abc.
As we know, Any class that extends the class “Pluggable” has the ability to call
$this->fireEvent('EventName');
and then plugins can attach to that event to perform an action.
In my case Both plugins are attached here:
$Sender->fireEvent('CommentOptions');
But the question is how can I get value from plugin xyz and abc seperately (because I need both values in different positions).
Is it possible?
If question is still not clear, I am happy to explain again.
I would appreciate your help!!
0
Comments
You cannot set the order in which the plugins will be executed. By now they would be executed alphabetically.
In the plugin that is executed first, you could use
Gdn::session()->stash('SomeUniqueKey', 'TheValueToKeep);
to store some value for this session and use$theStoredValue = Gdn::session()->stash('SomeUniqueKey');
to retrieve that value in the next plugin.you mean I have to make changes in the plugins? Is 'SomeUniqueKey' a random values?
If I haven't made myself clear then I am doing it again:
I am using plugin 'EasyReply' and 'I Like This ( Plugin )'. I get both these plugins values with $Sender->fireEvent('CommentOptions');
But I want 'EasyReply' link in one position and 'I Like This ( Plugin )' button in other position.
Is there a way to get these values saperately (I guess no as you said @R_J )?
If not then is there a way to get ?
Thank you again !!!
P.S: I am new in Vanillaforum
Oh, hoppla, das habe ich total falsch verstanden ;-)
Basically you want to reuse a piece of an existing plugin. That is not always possible. Sometimes you would have to create a third plugin which consists of code that you copy from the original plugins.
If you want to do anything at all you most probably would have to write your own plugin or theme, anyway. Create a new plugin and try this:
This will mess up your forum by displaying "I Like!" buttons at numerous places, but I just wanted to demonstrate how you could reuse other plugins. If you look at the "I Like This" plugin, you will see that the name of the class is "LikeThis". So what I have done above, was simply creating my own instance of this plugin and I called the method that is used inside that class to handle CommentOptions events, passing $sender, an instance of the calling class. That's it.
Since any event handler in a plugin must be a public method, it should be easy to use most of them that way (also EasyReply, which I don't use).
In some cases the markup might not be correct or they are manipulating/expecting EventArguments that your preferred event doesn't have. In such cases you would have to become somewhat more creative...
Don't hesitate to ask if you get stuck!
I'm wondering whether your title is misleading (of course it may be me who misreads your post...). Would the following title better describe your need:
"How to control the order of information placed in the meta area by the plugins I enable? "
Oops, R_J and I responded at the same time... Ignore my response...
@rbrahmson: different order? I do not hope that this is the question. That would be much more complicated!
@r_j: this sentence led me to believe he wanted to control the order of information in the meta area:
Regardless of the original intent, think your method (stash) could accomplish that irrespective of the order - as long as the developer knows which plugins are expected to "push data". Once all of them did their pushing, the last one receiving the info could actually echo it into the meta area.
I think I could actually create a general-purpose plugin for that purpose to be used by other plugins. But not now, too busy...
If all you want to do is change the location of the two items in the two plugins - you could probably easily do this with css and avoid any php changes.
Based on youy question, it seems that you just want to place one item before another. you might post an image of what you want to do.
Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.
Thank you. I will try this.
That would be great if you create plugins that will let you choose to get selected plugins value in a desired position.
I could also do with css, just write
$Sender->fireEvent('CommentOptions');
two times where needed and hide the unwanted classes (eg. in one place hide replyto button and in other hide like button) but I find this solution not very good.
Here you get like button and answer button with
$Sender->fireEvent('CommentOptions');
. But I want like button to the top and answer button (with 'Antworten' text) to the buttom.https://github.com/vanilla/vanilla/blob/7fcb213c7540d4c4fe04c3f6c0676f38df7e29e0/plugins/HtmLawed/class.htmlawed.plugin.php#L138
as an aside you may not be aware that turning off safestyles may be a bit unsafe and is coded to this in memory in the easyreply plugin.
SaveToConfig('Garden.Html.SafeStyles',FALSE);
Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.
I didnt understand what you mean. Can you please make it a bit clear.
@vanillawhisky: normalerweise schreibe ich ja hier auf Englisch, damit immer alle alles nachvollziehen können, aber weil ich doch noch ein wenig auf dem Schlauch stehe, was genau du zu erreichen versuchst, mache ich eine Ausnahme
Ich habe es so verstanden, dass du sowohl den "Antworten" Button, als auch das "I Like" Daumensymbol an einer anderen Stelle haben möchtest, als sie derzeit sind, oder? Der Screenshot zeigt vermutlich den Ist-Zustand an. Kannst du sagen, wo genau die beiden Dinger auftauchen sollen? Wenn du eine Zeichnung liefern kannst (mach einen Screenshot, kopier das in Paint und verschiebe die Elemente dort mittels Drag&Drop - muss ja nicht schön sein), können die anderen hier dir sicherlich auch helfen.
Generell würde ich sagen, kannst du die Elemente mit dem Code Schnippsel den ich oben gegeben habe zwar woanders auftauchen lassen, aber dafür zu sorgen dass sie an der jetztigen Position nicht mehr auftauchen ist deutlich schwieriger. Ggf. musst du dafür tatsächlich auf CSS zurückgreifen...
Danke für die Antwort. Es tut mir leid wenn Ich sage ich nicht so gut auf Deutsche schreiben kann aber verstanden schon
Here are the screnshots:
Like I said before with
$Sender->fireEvent('CommentOptions');
i get 'like' and 'answer' button as shown in second screenshot.But I want these two buttons in different positions like in figure first (like at top and answerbutton to the button).
At the moment i have done with absolute position in css. I can also write
$Sender->fireEvent('CommentOptions');
twice and get double so that I can hide those buttons which I dont need. But I dont want to do like that so asked for help.Servus!!!
Sorry, I though writing in German would be helpful!
Looking at your screenshots I'd say that all what you want is to place the EasyReply button to the bottom, correct? You seem to be all right with the placement of the I Like symbol.
The EasyPlugin echos html directly. So without changing the code of the plugin (which you shouldn't do!), there is no way to stop it from writing the html at that place. Although I hat to say it: in this case it might be the best to "solve" the problem with CSS.
There are three (?) other ways here that I just want to mention for the sake of completeness:
1. Change it with JavaScript - bad. Even worse than CSS.
2. Copy the plugin and create your own plugin which uses the AfterDiscussionBody event - well, given that the plugin isn't changed so often, this might be as good as the css solution.
3. You could write a plugin that will be executed before the CommentOptions event and deactives the plugin, and which re-enables and directly uses it in the AfterDiscussionBody event. This is the least invasive php solution, but I would still favor the css way.
Well, Thank you for your suggestion.
At last I came to the conclusion to create my own plugins (or at least try to) which is usefull in such conditions.
If not , there is always CSS.
Thanks to everyone.
Cheers !!!