Keyword

K2 Category Plugin developments

  • Dario Pintarić
  • Dario Pintarić's Avatar Topic Author
  • Offline
  • New Member
More
9 months 4 weeks ago - 9 months 4 weeks 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: 9 months 4 weeks 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
9 months 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
9 months 3 weeks ago #167292 by Krikor Boghossian
Krikor Boghossian 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
9 months 3 weeks ago - 9 months 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: 9 months 3 weeks ago by Dario Pintarić. Reason: Grammar nazzi :)

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

More
9 months 3 weeks ago #167332 by Krikor Boghossian
Krikor Boghossian 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.

  • Tomás Berjoyo Fernández
  • Tomás Berjoyo Fernández's Avatar
  • Offline
  • New Member
More
2 months 1 week ago #170230 by Tomás Berjoyo Fernández
Tomás Berjoyo Fernández replied the topic: K2 Category Plugin developments
Good morning Krikor,

I am developing a Plugin for k2 with the Items selector using the type "k2modalselector" like mod_k2_content module and it does not save the values of the selected items, resulting in an empty field. The rest of fields with type Text or Checkbox work perfectly, showing the stored fields when re-editing the item.

what am I doing wrong? Many thanks in advance for any kind of help and for the great K2 component that I have been using for years.

Regards,

Code fragment in the definition of the seletor field in the xml file of the plugin.
Joomla v.3.9.0
K2 v2.9.0

[...]
<fields group="item-other" addfieldpath="/administrator/components/com_k2/elements/" >
 <field type="k2modalselector" name="setItems" scope="items" default="" label="Selector de Item" description="Select items" />
[...]

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

  • Dario Pintarić
  • Dario Pintarić's Avatar Topic Author
  • Offline
  • New Member
More
2 months 1 week ago - 2 months 1 week ago #170232 by Dario Pintarić
Dario Pintarić replied the topic: K2 Category Plugin developments
I think you have to use the name "items", not "setItems" for the field name, because the field name is hardcoded in the script that adds items to the list....

I am 99% sure of this...
Last Edit: 2 months 1 week ago by Dario Pintarić.

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

  • Tomás Berjoyo Fernández
  • Tomás Berjoyo Fernández's Avatar
  • Offline
  • New Member
More
2 months 1 week ago #170244 by Tomás Berjoyo Fernández
Tomás Berjoyo Fernández replied the topic: K2 Category Plugin developments
Good morning to all, thank you very much Dario, but that does not solve the problem of not saving the field data. I would not like to leave this selection of items in the hands of a text field for the users. My k2plugin has only two files (php / xml) Any other idea? Thank you

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

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
2 months 1 week ago #170260 by Fotis
Fotis replied the topic: K2 Category Plugin developments
The element/field works just fine. There is no limitation to the "name" value of course.

It's what happens when you "save" the item edit form. Or when you read the plugin data.

In Joomla 3.8.x+ I noticed that fetching the plugin data in the item form only works when you don't specify the 3rd parameter here:
$plugins = new K2Parameter($item->plugins, '', ''); // Setting $this->pluginName as 3rd parameter does not work in J3.8.x)

Can you show the main php code of the plugin please?


If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

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

  • Tomás Berjoyo Fernández
  • Tomás Berjoyo Fernández's Avatar
  • Offline
  • New Member
More
2 months 6 days ago #170297 by Tomás Berjoyo Fernández
Tomás Berjoyo Fernández replied the topic: K2 Category Plugin developments
it's strange, but without 3rd param in $plugins = new K2Parameter($item->plugins, '', '') does not get any value from fields (null) and fieldtype k2modalselector still not saving data. Joomla v3.9.0 / K2 v2.9 / PHP v7.1

Here is my K2plugin to insert items into item, now working width a text field for input items ID comma separated and including the field k2modalselector:

File Attachment:

File Name: iteminitem.zip
File Size:4 KB


Regards and thank you very much, Fotis
Attachments:

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

Moderators: william white