How do I have joomla run some script every time a k2 item is created?

39 views
Skip to first unread message

Shenk Wen

unread,
May 2, 2016, 2:20:55 PM5/2/16
to Joomla! General Development
I am using k2 to build my Joomla 3.5 site. My k2 items are basically youtube videos, every youtube video has a URL pattern for its preview image and I want it to be the item's image. But I don't want to bother with the repetitive job (copying the video ID, fitting it into the URL, and saving it as the item's image) every time I create an item. So I am thinking maybe I can write some script to automatically get the images(it is easy to do once the video's id is provided). The problem is, this script has to be exectued every time I create an item.

I just start to learn some basic things about Joomla extension developing, my question is, which category does the thing I want to fall into? Shall it be a plugin? Or a k2 plugin? Or there is totally no interface for this kind of thing and I will have to hack some PHP file?

Furthermore, I also have some node.js script to scrape the description of the Youtube videos(Yes I am being lazy again, I don't want to copy and paste those descriptions every time I create an item). How do I get Joomla to run these node.js scripts?

muhakh

unread,
May 6, 2016, 1:03:10 PM5/6/16
to Joomla! General Development
I think it will be a plugin would be your solution. You can use "onContentBeforeSave" which is an event that is triggered before the item is saved. You can then check if the context = 'com_k2.item' and if true, you tell your plugin to run your script "I suggest using JHTML class to do this job".
Reply all
Reply to author
Forward
0 new messages