• Register or
  • Sign In
    • Forgot your password?
    • Forgot your username?
    Or sign in with your account on:
    Facebook
    Twitter
    Google
    LinkedIn

K2 | The powerful content extension for Joomla! developed by JoomlaWorks

  • home
  • about
  • blog
  • documentation
  • extend K2
  • showcase
  • community
  • demo
K2 brings the good parts from Drupal and Wordpress into Joomla!
  • Index
  • Recent Topics
  • Search
Welcome, Guest

To post messages, you need to login first.
K2 Community Forum
K2 Community Forum
New to K2? Ask here first!

plugin documentation?
(1 viewing) (1) Guest
Reply Topic
New Topic
  • Page:
  • 1

TOPIC: plugin documentation?

plugin documentation? 11 months, 1 week ago #158917

  • Jerry
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 15
Hi,

It seems I am not going to solve my problems just by using Extra Fields and from what I read I need to write a K2 plugin. I am a php programmer so that is not a problem, but I need some documentation on how to set things up.

I have downloaded the K2 Plugin Example, but some things are still not clear. For example, the class definition. Is this the correct syntax?
class plgK2MyPluginName extends K2Plugin {
function plgK2MyPluginName( & $subject, $params) {
parent::__construct($subject, $params);
}
}


Then I see the following functions / triggers:
onK2PrepareContent
onK2AfterDisplay
onK2BeforeDisplay
onK2AfterDisplayTitle
onK2BeforeDisplayContent
onK2AfterDisplayContent
onK2CategoryDisplay
onK2UserDisplay


I can't find any trigger names I can use when the user is submitting a front-end form. I need to do stuff like generating a title The item is for an event and contains a date and time and a description that might be empty. I need a generated title so it will give enough information for the admins when they check the list of items.
Also, the Publish Down date should be the event date + 7 days, the category is hidden (set in the menu item to add an event).

I want control of those basic joomla fields and not bother the user with that. I assume that is only possible in an OnSave event function. The plugin description mentions 6 events available for editing. But why can I not find any info on this?

Next, what is the DOM so I can access the item's properties, read extra fields from the database and save them in the item (or just on the screen) before editing its values and reading them back for writing into the database on Save?

Thanks!!
Jerry
Last Edit: 11 months, 1 week ago by Jerry.
Reply Quote

Re: plugin documentation? 11 months, 1 week ago #158942

  • Lefteris Kavadas
  • ( Admin )
  • OFFLINE
  • Administrator
  • Posts: 2226
Hi. There are two plugin events that may help you:

onBeforeK2Save($item, $isNew)


and

onAfterK2Save($item, $isNew)


They are triggered right before and after K2 saves an item.
Reply Quote

Re: plugin documentation? 11 months, 1 week ago #159149

  • Jerry
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 15
OK, great, I am a few steps further now, thanks.

Next problem is I can't find any info on how to access the extra fields here.

I can read the $_POST, but I only get keys like this:
K2ExtraField_1
K2ExtraField_2

Is there a way to get the extra field definitions from the $item here?

Thanks!
Jerry
Reply Quote

Re: plugin documentation? 11 months, 1 week ago #159193

  • Lefteris Kavadas
  • ( Admin )
  • OFFLINE
  • Administrator
  • Posts: 2226
You have the whole item available. So you can try something like that:

json_decode($item->extra_fields)
Reply Quote

Re: plugin documentation? 11 months, 1 week ago #159218

  • Jerry
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 15
Maybe something is wrong, because $item->extra_fields is NULL in onBeforeK2Save.
Reply Quote

Re: plugin documentation? 11 months ago #159263

  • Lefteris Kavadas
  • ( Admin )
  • OFFLINE
  • Administrator
  • Posts: 2226
If it's a new item it will be null on the BeforeSave event. You need to take a look at the /administrator/component/com_k2/models/item.php to see how you can get it from the POST data. But, as i have mentioned again you do not need to handle this. K2 will save those fields automatically. You can manipulate them in the AfterSave event. Also do not post duplicate posts.
Reply Quote
Reply Topic
New Topic
  • Page:
  • 1
K2 Community Forum
K2 Community Forum
New to K2? Ask here first!
Find this topic helpful? Why not share it with others?
Tweet
Powered by Kunena
Time to create page: 0.40 seconds
Advertisement
  • Contact us
  • Join the K2 Expert Companies list
  • Privacy Policy
back to top
Copyright © 2006 - 2013 JoomlaWorks Ltd.. All rights reserved. K2 is a joint project by JoomlaWorks Ltd. & Nuevvo Webware Ltd., released under the GNU/GPL v2 license.
Joomla! is a registered trademark of Open Source Matters, Inc. JoomlaWorks/Nuevvo are not affiliated with or endorsed by Open Source Matters or the Joomla! Project.
designed by Nuevvo