• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Unable to extend XenForo_ControllerAdmin_Forum

Mr. Goodie2Shoes

Well-known member
#1
Hello,
I am trying to extend the Controller... but for some weird reason, its not working...
This is the listener:
PHP:
    public static function loadClassListener($class, array &$extend)
    {
        switch($class)
        {
            case 'XenForo_ControllerAdmin_Forum':
                $extend[] = 'GFNCoders_XenSocialize_ControllerAdmin_ForumExtended';
                break;
        }
    }
and this is the 'extension':
PHP:
class GFNCoders_XenSocialize_ControllerAdmin_ForumExtended extends XFCP_GFNCoders_XenSocialize_ControllerAdmin_ForumExtended
{
    public function actionSave()
    {
        $return = parent::actionSave();
        $nodeId = str_replace('#_', '', strstr($return->redirectTarget, '#_'));
        
        $writerData = $this->_input->filter(array(
                'enable_xensocialize' => XenForo_Input::UINT,
                'enable_twitter' => XenForo_Input::UINT,
                'twitter_preface' => XenForo_Input::STRING,
                'twitter_postface' => XenForo_Input::STRING,
                'enable_facebook' => XenForo_Input::UINT,
                'facebook_preface' => XenForo_Input::STRING,
                'facebook_postface' => XenForo_Input::STRING,
        ));
        
        $writer = $this->_getNodeDataWriter();
        $writer->setExistingData($nodeId);
        
        $writer->bulkSet($writerData);
        $writer->save();
        
        return $return;
    }
}
and no, I don't get any error. :(
 

Mr. Goodie2Shoes

Well-known member
#2
okay... I just used the _preSave() function like this:
PHP:
    protected function _preSave()
    {
        $_input = new XenForo_Input($_REQUEST);
        
        $extraData = $_input->filter(array(
                'enable_xensocialize' => XenForo_Input::UINT,
                'enable_twitter' => XenForo_Input::UINT,
                'twitter_preface' => XenForo_Input::STRING,
                'twitter_postface' => XenForo_Input::STRING,
                'enable_facebook' => XenForo_Input::UINT,
                'facebook_preface' => XenForo_Input::STRING,
                'facebook_postface' => XenForo_Input::STRING,
        ));
        
        $this->bulkSet($extraData);
        
        return parent::_preSave();
    }
}
is there any other workaround?
 

Jake Bunce

XenForo moderator
Staff member
#3
Extending the controller should work. I extend the same controller in the Nodes As Tabs addon. I use slightly different logic though. I check the redirect type. Then I query the node_id if it's not in the input. If the node_id isn't in the input then that means you have just added a new forum (as opposed to editing an existing forum) so you need to query the highest used node_id to get the id for the newly added forum:

Code:
<?php

class NodesAsTabs_ControllerAdmin_AllNodes extends XFCP_NodesAsTabs_ControllerAdmin_AllNodes
{
	public function actionSave()
	{
		$response = parent::actionSave();

		if ($response->redirectType == XenForo_ControllerResponse_Redirect::SUCCESS)
		{
			$nodeData = $this->_input->filter(array(
				'node_id' => XenForo_Input::UINT,
				'nat_display_tab' => XenForo_Input::UINT,
				'nat_display_tabperms' => XenForo_Input::UINT,
				'nat_tabtitle' => XenForo_Input::STRING,
				'nat_display_order' => XenForo_Input::UINT,
				'nat_position' => XenForo_Input::STRING,
				'nat_childlinks' => XenForo_Input::UINT,
				'nat_childlinksperms' => XenForo_Input::UINT,
				'nat_markread' => XenForo_Input::UINT,
				'nat_linkstemplate' => XenForo_Input::STRING,
				'nat_popup' => XenForo_Input::UINT,
				'nat_tabid' => XenForo_Input::STRING
			));

			if (empty($nodeData['node_id']))
			{
				$db = XenForo_Application::get('db');
				$nodeData['node_id'] = $db->fetchOne("
					SELECT node_id
					FROM xf_node
					ORDER BY node_id
					DESC
				");
			}

			$optionsModel = $this->_getOptionsModel();

			// $nodeData['nat_childnodes'] = $optionsModel->buildChildList($nodeData['node_id']);
			// $nodeData['nat_firstchildnodes'] = $optionsModel->buildFirstChildList($nodeData['node_id']);

			$optionsModel->saveOptions($nodeData);

			$optionsModel->deleteOrphans();
			$optionsModel->rebuildCache();
		}

		return $response;
	}
}
 

xfrocks

Well-known member
#4
I have extended XenForo_ControllerAdmin_Forum::actionSave() before, you should be able to do it. Try to put in some debug output.