Keyword

Create Front-End Category Edit

More
10 years 7 months ago #124739 by Sean
Create Front-End Category Edit was created by Sean
Hello,

I am wanting to add front-end edit functionality that will allow a user to edit a category. I know this is not currently part of K2.

I was wondering if someone can give me an explanation of how the front-end item edit works so I can use it as a starting point.

I realize I will need to create a categoryform.php (itemform.php equivalent) that will sit in the default view (as an override). I will also need to add the category edit links, similar to item edit links to the required k2 template views.

The main question I have is regarding the actual link in question.

For the item edit the link displays as follows:
domain/index.php/item-alias/item/edit/item-id?tmpl=component

(The portions in bold change per link/site etc)

What I would like to know if possible is where this link is directed, meaning what is directing the link to the itemform.php file to actually edit it?

The end goal I am trying to achieve is to allow a user to edit a category name & alias, description and image. I don't need to worry about category settings or the rest. I do know I can make the necessary changes to the the categoryform.php file I will need to make.

Thanks to anyone who can help shed some light on where to start with this some what lofty goal. I will provide any additional info/details needed.

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

More
10 years 7 months ago - 10 years 7 months ago #124740 by Sean
Replied by Sean on topic Re: Create Front-End Category Edit
After doing some digging I believe I found the correct file that is directing the Front-end Edit Link to the itemform.php file.

../components/com_k2/controllers/item.php

Lines 83 - 142 cover 'function edit', and specifically lines 112-115 appear to be directing the link to itemform.php.

(Lines 112-115)
$this->addViewPath(JPATH_COMPONENT_ADMINISTRATOR.DS.'views');
$this->addModelPath(JPATH_COMPONENT_ADMINISTRATOR.DS.'models');
$view = $this->getView('item', 'html');
$view->setLayout('itemform');

I will continue to investigate. If anyone is able to confirm that this is the correct file for redirecting to itemform.php for Front-end Editing it would be greatly appreciated.

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

More
10 years 7 months ago #124741 by Sean
Replied by Sean on topic Re: Create Front-End Category Edit
To elaborate, inside the item.php and categoryitem.php template files is a php statement:
<?php echo $this->item->editLink; ?>

That code snippet is pointing to the item.php file at:
../components/com_k2/models/item.php

..where on lines 102-104 of item.php,the specifics of the edit link are stated:
//Edit link
if (K2HelperPermissions::canEditItem($item->created_by, $item->catid))
$item->editLink = JRoute::_('index.php?option=com_k2&view=item&task=edit&cid='.$item->id.'&tmpl=component');

Inside the $item->editLink variable are:

"view=item" ..which is pointing to ../components/com_k2/controllers/item.php

&

"task=edit&cid" which is pointing to the "function edit" (edit) and "function extraFields() (cid) of the item.php controller.

Now that I have a better understanding of what is happening underneath the hood, I am proposing creating the following files:

/components/com_k2/controllers/category.php (this will declare the functions for editing a category)
/components/com_k2/models/category.php (this will declare the variable $category->editLink and include the category controller file).
/components/com_k2/templates/default/categoryform.php (the actuall category edit page for the front-end).

It is also possible to place the file 'categoryform.php' as an override in:
../templates/YOURTEMPLATE/html/com_k2/default/categoryform.php

I am hoping by creating new files and not making changes to existing files I will be able to simply re-upload my created files upon a new k2 release with minimal issues. Once I can get to a working solution I wouldn't mind sharing the files with K2 to include in a future release if possible. Maybe wishful thinking. :cheer:

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


Powered by Kunena Forum