K2 Community

Join the network of the powerful content component for Joomla!

[UPDATED FOR v2.1+]

If you don't know already, K2 version 2+ features a new plugin API to easily extend the forms used for items, categories and user profiles.

That means you can write a simple plugin to add additional fields and extend K2 forms beyond "extra fields".

The K2 plugin API features 6 identical to Joomla's plugin events for the frontend with the "onK2" prefix instead of "on", 2 events for frontend display in category and user pages, plus 2+6 more events for the backend, which are used to extend the backend forms for item (one for each tab of the item form plus one generic), category and user.

Since we're basically adding fields in the backend for these 3 forms, we need to define these fields somewhere. We do so inside the XML of the plugin by defining additional "groups" of parameters.

If we want to extend the item form for example, we create a new parameter group with the name "item-content" or "item-video" (where the second part targets a specific tab in the item form). In a similar fashion, we create groups for "category" and "user". We then write in these groups our new fields (you can use all available fields options provided by Joomla!, including custom content elements) and that is how we extend K2's forms.

Download the example plugin we provide and examine the code. This example plugin adds an extra field where you can input a YouTube URL and it will automatically convert it to a video in the frontend. You enter this URL inside all 3 forms in K2 (item, category, user).

In-depth tutorials will be provided as documentation progresses. In the meantime, watch the K2 presentation video where we talk about K2 plugins and what they can do: http://k2community.joomlaworks.gr/video/k2-presentation-and-more-at

Try it out and let us know your thoughts and comments.

The plugin installs via Joomla! extension installer.

K2 plugins are installed inside the "/plugins/K2/" folder in your Joomla! site.

Tags: example, k2, plugin, youtube

Attachments:

Reply to This

Replies to This Discussion

I have created plugin using your example plugin, works fine till now but few things I want to know if possible:

1. currently it just add fieldsets under tab plugins, can I have my own tab name in item entry form.
2. I want to have a new field with HTML editor to put html in is possible, though I tried using some joomla core plugin enhancements (like elements folder and putting my custom param type and defining that as php file in elements folder), but didn't work for me seems like it can just work for parameters in joomla plugin manager.

Reply to This

Well i am NOt a programmer. But i have tryed to create a k2 plugin from the example.
Well please take a look at it and tell me how to make this work with 2.2

I do not have any way of testing this. dont know if it will work at all. But here it is.
Attachments:

Reply to This

I have the latest version of Joomla, and the latest version of K2. I downloaded the plugin and enable it, but I do not see anything in the backend item editor that indicates the plugin was installed. Does the plugin work with 2.2? I have some plugins I would like to create and was looking forward to examining your example.

UPDATE: The plugin IS working. It is under the Video tab, and under the JoomlaWorks AllVideos information.

Reply to This

Reply to This

RSS

Advertisement

Latest Activity

Matthew Santana added a discussion
Hello! I'm relatively new to web development and I have to admit that Joomla! and K2 have made it a rewarding experience. There are so many possibilities. That being said I hate to make my first post here about an error however it is getting in the…
5 minutes ago
Matthew Santana, Kibekas, Ninja B and 2 more joined K2 Community
10 minutes ago
Not sure how the rest would be affedcted but creating a table to join category ID's is pretty simple as far as database modeling goes ... That being said, I don't wan't to judge how and why it's the way it is, it simply is :-) Maybe the developpers…
10 minutes ago
Plz send a link if site is live
2 hours ago
See the k2 menu choices at the bottom - latest from user or categories select the category and set the number of items and it will work
2 hours ago
FidelGonzales added a discussion
I'm having some issues getting my categories to appear properly. The culprit seems to be the following code: . In default form, there is a huge gap on the top of the category page. After removing a few of these, the issue is partially fixed with cer…
2 hours ago
someone better that i may can tell you, try commenting the div class clr's our and see what happens
2 hours ago
Thanks for the reply. Unfortunately I'm not so experienced with Firebug nor CSS. I attached a new image, where one can see more information. Does this help a bit more?
2 hours ago
Whatever is done will modify the core, but will work. How about putting the category id's in a field like the xtra filelds and teach the core to parse them out. Its changing the way things work - not likely to happen unless a module like followeyes…
2 hours ago
I don't think the concept of the single-category per item content structure is a way of thinking that is advanced and, therefore, a reason to change the content construction strategy and our subsequent way of thinking. It is merely a huge limitation…
2 hours ago
2. if you are trying to remove a video from an item in the backend, click on the video tab scroll to the bottom and check delete currrent and save
3 hours ago
Please post a link if the site is live Use firebug to see what there and what needs to be changed
3 hours ago
Also, to skip the extra field you dont want edit in the override item.php and put something like {pseudocode} phpif this->extrafield->name="fieldyouwantto skip" else let the rest of the existing foreach loop run phpendif endfor something like that s…
3 hours ago
Kibekas added a discussion
There is a problem with excess of free space between 'itemListSubCategories' and 'itemList'. It seems to be derving from div class 'itemlistsubcategories' Please see the image attached. Does anyone know how to solve this problem? Via CSS?Thanks!
3 hours ago
you can get the extra fields like this if it suits your needs $custom = $this->item->extra_fields; and then addressing extra fields for the item like echo $custom[1]->value; depending on the position, 0, 1,2,3,4 etc in the array experiment with this…
3 hours ago
deton and Daito joined JoomlaWorks's group
For K2 translators
3 hours ago
I can translate to Russian
3 hours ago
I have a case right now where I would love to be able to set several categories for one article. For now, it has been solved with the use of tags, and I suspect this is how we will have to use it in the future. It might just be that we are used to…
3 hours ago
Viktoria (and Simon), Did you ever find out how to put one single extra field (not the whole bunch...) a different place than at the bottom of the article? This means we need to have a way to identify this particular field and add the code for it…
3 hours ago
Valentine added a discussion
Greetings to all . So here is what i cant understand1. i Cant login as an admin tru k2 login in frontend form just resets and i see begining of page2. I cant understand how to remove Related videos Any help will be good thanks in advance
4 hours ago

© 2010   Created by JoomlaWorks.

Badges  |  Report an Issue  |  Terms of Service