Search code examples
phpjoomlajoomla3.0

Joomla 3.x Override button functions in custom component


I'm trying to override the buttons in my joomla component.

I've managed fine with the save function by adding code into the controller.

            public function save($key = null, $urlVar = null)
                {
                    $uri = JUri::getInstance(); 


                    $requestData = JRequest::getVar('jform', array(), 'post', 'array');
                    $user =& JFactory::getUser();
                    $userId = $user->get( 'id' );

                    $idToUse = $requestData['id'];

I want to do the same thing with save and close and save and new but I can't figure out how to do it. I thought that I needed to go to the view.html and look at the custom functions:

            JToolBarHelper::title(JText::_('COM_SHOPPER_TITLE_SELECTOR'), 'selector.png');

            // If not checked out, can save the item.
            if (!$checkedOut && ($canDo->get('core.edit') || ($canDo->get('core.create'))))
            {
                JToolBarHelper::apply('selector.apply', 'JTOOLBAR_APPLY');
                JToolBarHelper::save('selector.save', 'JTOOLBAR_SAVE');
            }

            if (!$checkedOut && ($canDo->get('core.create')))
            {
                JToolBarHelper::custom('selector.save2new', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
            }

So I thought I just needed to add a function save2new() but I can't figure out how to make it work.

Any thoughts on where I'm going wrong would be great.


Solution

  • I guess you are looking for registerTask.

    If you want to call save method for save2new task than you need to call registerTask inside constructor __constructor

    $this->registerTask('save2new', 'save');
    

    https://docs.joomla.org/API17:JController::registerTask