Search code examples
joomlajoomla2.5joomla-k2

Joomla - Where is the code in K2 which saves a new item's Title and alias


I have looked every where in the administrator\components\com_k2 folder but am not able to find the code that saves a new item\article in K2. I checked the item.php file under models folder. No luck.

I need to override the K2 item save method.

I need a know the exact method that saves the Item's title and alias into the #__K2_content table.

I have to duplicate the K2 items in joomla articles on save and remove on trash/delete.

I have successfully been able to override the K2 core code. But am unable to find the right code to override. (override method is here)


Solution

  • The table that stores the K2 items (at least in the latest K2 version - 2.6.5) is #__k2_items, not #__k2_content.

    I went through the code, it looks like K2 uses Joomla's methods: see administrator/components/com_k2/controllers/item.php - line 24: function save(). Everything is extended from Joomla classes.

    class K2ControllerItem extends K2Controller
    {
    
        public function display($cachable = false, $urlparams = array())
        {
            JRequest::setVar('view', 'item');
            parent::display();
        }
    
        function save()
        {
            JRequest::checkToken() or jexit('Invalid Token');
            $model = $this->getModel('item');
            $model->save();
        }
        .....
    }
    

    The K2 controller: /administrator/components/com_k2/controllers/controller.php

    ...
    else if (version_compare(JVERSION, '2.5', 'ge'))
    {
        class K2Controller extends JController
        {
            public function display($cachable = false, $urlparams = false)
            {
                parent::display($cachable, $urlparams);
            }
    
        }
    
    }
    ...