Keyword

K2 Category Plugin developments

  • Dario Pintarić
  • Dario Pintarić's Avatar Topic Author
  • Offline
  • New Member
More
2 months 1 day ago - 2 months 1 day ago #167250 by Dario Pintarić
Dario Pintarić created the topic: K2 Category Plugin developments
Hi all...

I'm facing a weird problem in K2 category.... I've developed a K2 plugin that basicly let's you select any articles that you wan't to show on the category list (via slightly modified k2modalselector field type).

Now the problem is.... when i select 1 or more articles - the plugin params get saved.....

Imagine we just selected an article with ID 1 and 2... all well, my params get saved....

Now after it's saved once, if i remove those two articles - so i have no articles selected - they magicaly reappear......

The delete itself works ok, but the problem is when there are no items selected - but were selected and saved before - K2 will totally ignore plugin database colum since there were no plugin inputs on the admin form....

Let me remind yout that when you select an item with k2modalselector - it will add hidden input for every article.... but if no articles were selected - there are no inputs....

I've "fixed" this by editing /administrator/components/com_k2/models/category.php and changing the line
if (!$row->bind(JRequest::get('post')))

into
$post = JRequest::get('post');
if(!isset($post['plugins']))
	$post['plugins'] = array();

if (!$row->bind($post))

because "plugins" array key is not set inside POST, and therefore (probably) doesn't get updated in the table....

What i did is a K2 core hack, and i don't wanna do this....

So my question is... Am i doing something wrong or is it a K2 bug ?

How do i reset plugin value to be "none" / "empty" or entirely remove plugin params from the plugins database column ?
Attachments:
Last Edit: 2 months 1 day ago by Dario Pintarić.

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

  • Dario Pintarić
  • Dario Pintarić's Avatar Topic Author
  • Offline
  • New Member
More
1 month 3 weeks ago #167290 by Dario Pintarić
Dario Pintarić replied the topic: K2 Category Plugin developments
Never mind.... i got it.....

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

More
1 month 3 weeks ago #167292 by Krikor
Krikor replied the topic: K2 Category Plugin developments
What was the issue?

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

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

  • Dario Pintarić
  • Dario Pintarić's Avatar Topic Author
  • Offline
  • New Member
More
1 month 3 weeks ago - 1 month 3 weeks ago #167311 by Dario Pintarić
Dario Pintarić replied the topic: K2 Category Plugin developments
Well, since K2 will only "react" to plugins if an input value is actually present and passed in POST, I've inserted a hidden input with the same name and an empty value - just not array....

S i did
<input name="jform[someinputname]" value="" />

before the K2modalselector ordered list - which inserts hidden inputs - but as an array...
<input name="jform[someinputname][]" value="1"/>
<input name="jform[someinputname][]" value="2"/>

And then when you delete all the articles/tems, an empty value of the same variable name will be passed, and if you selected anything - the first set variable name gets "overridden" with the array of values after it (containing the same name)...

Works like a charm - and no K2 core hacks :)
Last Edit: 1 month 3 weeks ago by Dario Pintarić. Reason: Grammar nazzi :)

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

More
1 month 3 weeks ago #167332 by Krikor
Krikor replied the topic: K2 Category Plugin developments
Kudos Dario!!!

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

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

Moderators: william white