COMMUNITY FORUM
Add K2 Item editor-xtd Button
- Geraldo de Oliveira
- Topic Author
- Offline
- New Member
Less
More
4 years 6 months ago #175677
by Geraldo de Oliveira
Add K2 Item editor-xtd Button was created by Geraldo de Oliveira
Hello everyone,
I can't argue about how powerful JCE Editor is but I just don't like and seems that there's no way to avoid JCE from removing the html code format and I need to link some K2 Items in some content so my idea was to create a button editor-xtd.
I'm almost there: I get the modal and (perhaps) figured out the functions to call (k2ModalSelector). Of course I don't wan to edit core files so maybe I could work in the button file editing the K2 function.
But I can't print anything on the article.
I'll attach the zip file (k2ItemLink.zip) of the plugin for installation.
Would someone please help me out? What am I missing?
Thanks a lot!
Geraldo
I can't argue about how powerful JCE Editor is but I just don't like and seems that there's no way to avoid JCE from removing the html code format and I need to link some K2 Items in some content so my idea was to create a button editor-xtd.
I'm almost there: I get the modal and (perhaps) figured out the functions to call (k2ModalSelector). Of course I don't wan to edit core files so maybe I could work in the button file editing the K2 function.
But I can't print anything on the article.
I'll attach the zip file (k2ItemLink.zip) of the plugin for installation.
Would someone please help me out? What am I missing?
Thanks a lot!
Geraldo
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
4 years 6 months ago #175680
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Add K2 Item editor-xtd Button
This is tricky...
a) You need load JS code that utilizes "jInsertEditorText" which inserts text into the editor. Example: stackoverflow.com/questions/18761094/joomla-insert-text-in-editor-through-a-plugin
b) When clicking on a K2 item, a function "k2ModalSelector" is triggered on the parent window of the modal (=the item edit form window). In your case, you would have to override this function (example for overriding a JS function stackoverflow.com/questions/5409428/how-to-override-a-javascript-function). Of course this inserts a piece of text in your current selection. If you construct an actual HTML link in your own "k2ModalSelector" function, I don't know if it will actually be inserted as HTML or as plain text in the WYSIWYG editor.
Perhaps it's just easier to use the JCE plugin for K2: getk2.org/extend/extensions/k2-links-for-jce
a) You need load JS code that utilizes "jInsertEditorText" which inserts text into the editor. Example: stackoverflow.com/questions/18761094/joomla-insert-text-in-editor-through-a-plugin
b) When clicking on a K2 item, a function "k2ModalSelector" is triggered on the parent window of the modal (=the item edit form window). In your case, you would have to override this function (example for overriding a JS function stackoverflow.com/questions/5409428/how-to-override-a-javascript-function). Of course this inserts a piece of text in your current selection. If you construct an actual HTML link in your own "k2ModalSelector" function, I don't know if it will actually be inserted as HTML or as plain text in the WYSIWYG editor.
Perhaps it's just easier to use the JCE plugin for K2: getk2.org/extend/extensions/k2-links-for-jce
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Geraldo de Oliveira
- Topic Author
- Offline
- New Member
4 years 6 months ago - 4 years 6 months ago #175681
by Geraldo de Oliveira
Replied by Geraldo de Oliveira on topic Add K2 Item editor-xtd Button
Ok, but it kinda working.
I was forgetting to put $name in the line window.parent.jInsertEditorText(tag, '$name');
And after configuring the variable now I can print in the editor the item URL but the function k2ModalSelector only gives id and name and I also need other parameters like alias and ItemId because K2 Item URL is like
index.php?option=com_k2&view=item&id=K2_ITEM_ID:K2_ITEM_ALIAS&Itemid=JOOMLA_MENU_ID
If only there's a way to the the ID through that function as a PHP variable, maybe I could get all the others parameters accessing the JTable function.
I was forgetting to put $name in the line window.parent.jInsertEditorText(tag, '$name');
And after configuring the variable now I can print in the editor the item URL but the function k2ModalSelector only gives id and name and I also need other parameters like alias and ItemId because K2 Item URL is like
index.php?option=com_k2&view=item&id=K2_ITEM_ID:K2_ITEM_ALIAS&Itemid=JOOMLA_MENU_ID
If only there's a way to the the ID through that function as a PHP variable, maybe I could get all the others parameters accessing the JTable function.
Last edit: 4 years 6 months ago by Geraldo de Oliveira.
Please Log in or Create an account to join the conversation.
- Geraldo de Oliveira
- Topic Author
- Offline
- New Member
4 years 6 months ago #175684
by Geraldo de Oliveira
Replied by Geraldo de Oliveira on topic Add K2 Item editor-xtd Button
Hi Fotis,
Thanks for your reply.
Yes, I've found out the function k2ModalSelector. I just call it in the button and add the function jInsertEditorText to insert the text and it works!
Now my problem is that K2 routing requires other parameters like item alias and menu id. I'll try to dig it more.
I know there's K2 links for JCE but unfortunately it breaks the HTML format (indentation etc) and on this website I'm working on, loosing that format means loosing my mind in a near future XD
Thanks for your reply.
Yes, I've found out the function k2ModalSelector. I just call it in the button and add the function jInsertEditorText to insert the text and it works!
Now my problem is that K2 routing requires other parameters like item alias and menu id. I'll try to dig it more.
I know there's K2 links for JCE but unfortunately it breaks the HTML format (indentation etc) and on this website I'm working on, loosing that format means loosing my mind in a near future XD
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
4 years 6 months ago #175686
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Add K2 Item editor-xtd Button
Just the ID of the item should be sufficient.
See how it's fetched here: /components/com_k2/helpers/route.php
See how it's fetched here: /components/com_k2/helpers/route.php
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Geraldo de Oliveira
- Topic Author
- Offline
- New Member
4 years 6 months ago #175687
by Geraldo de Oliveira
Replied by Geraldo de Oliveira on topic Add K2 Item editor-xtd Button
That's what I've though but it doesn't work.
I get to print index.php?option=com_k2&view=item&id=94 where 94 is the correct item id
But Joomla somehow route this link into /component/k2/item/94. Even on K2 pages such as category or items.
I get to print index.php?option=com_k2&view=item&id=94 where 94 is the correct item id
But Joomla somehow route this link into /component/k2/item/94. Even on K2 pages such as category or items.
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
4 years 6 months ago #175689
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Add K2 Item editor-xtd Button
Perhaps a K2 plugin which "onK2AfterSave" could parse the output and pass all such URLs through JRoute::_(K2HelperRoute::getItemRoute($row->itemID)).
There are all the K2 plugin events by the way...
There are all the K2 plugin events by the way...
onK2AfterDisplay
onK2AfterDisplayContent
onK2AfterDisplayTitle
onK2AfterDownload
onK2BeforeAssignColumns
onK2BeforeAssignFilters
onK2BeforeDisplay
onK2BeforeDisplayContent
onK2BeforeDownload
onK2BeforeSetQuery
onK2BeforeViewDisplay
onK2CategoryDisplay
onK2CommentsBlock
onK2CommentsCounter
onK2PrepareContent
onK2UserDisplay
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Geraldo de Oliveira
- Topic Author
- Offline
- New Member
4 years 6 months ago #175695
by Geraldo de Oliveira
Replied by Geraldo de Oliveira on topic Add K2 Item editor-xtd Button
Thanks Fotis,
I'll try to have a look today or tomorrow.
Have a nice weekend!
I'll try to have a look today or tomorrow.
Have a nice weekend!
Please Log in or Create an account to join the conversation.
- JoomlaWorks
- Offline
- Admin
Less
More
- Posts: 6218
4 years 6 months ago #175699
by JoomlaWorks
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by JoomlaWorks on topic Add K2 Item editor-xtd Button
You're welcome.
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.