Keyword

plugin documentation?

More
11 years 10 months ago - 11 years 10 months ago #100665 by Jerry
plugin documentation? was created by Jerry
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

Please Log in or Create an account to join the conversation.

More
11 years 10 months ago #100666 by Lefteris
Replied by Lefteris on topic Re: plugin documentation?
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.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
11 years 10 months ago #100667 by Jerry
Replied by Jerry on topic Re: plugin documentation?
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

Please Log in or Create an account to join the conversation.

More
11 years 10 months ago #100668 by Lefteris
Replied by Lefteris on topic Re: plugin documentation?
You have the whole item available. So you can try something like that:
json_decode($item->extra_fields)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
11 years 10 months ago #100669 by Jerry
Replied by Jerry on topic Re: plugin documentation?
Maybe something is wrong, because $item->extra_fields is NULL in onBeforeK2Save.

Please Log in or Create an account to join the conversation.

More
11 years 10 months ago #100670 by Lefteris
Replied by Lefteris on topic Re: plugin documentation?
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.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum