Have No Idea How To Get Mod Working!

Anthony Parsons

Well-known member
I am trying to make is easier to use Jaxels user ranks, by putting them into a style property and hook, however; by trying to use the hook vs. template edit calling the additional template directly, it creates errors for me, obviously as some parameters must be parsed via the hook. Hence the area I have no idea about....

If I add to message_user_info directly the below, without using the hook, then it works fine.

<xen:if is="@jaxelUserRanksActive"><xen:include template="jaxel_userranks" /></xen:if>

But trying to use the hook message_user_info_text, then I get the following errors from the attached mod.

Code:
Template Errors: jaxel_userranks
Argument 1 passed to XenForo_Template_Helper_Core::helperIsMemberOf() must be an array, null given in /Applications/MAMP/htdocs/library/XenForo/Template/Helper/Core.php, line 1146
Argument 1 passed to XenForo_Model_User::isMemberOfUserGroup() must be an array, null given, called in /Applications/MAMP/htdocs/library/XenForo/Template/Helper/Core.php on line 1154 and defined in /Applications/MAMP/htdocs/library/XenForo/Model/User.php, line 1379
Argument 1 passed to XenForo_Template_Helper_Core::helperIsMemberOf() must be an array, null given in /Applications/MAMP/htdocs/library/XenForo/Template/Helper/Core.php, line 1146
Argument 1 passed to XenForo_Model_User::isMemberOfUserGroup() must be an array, null given, called in /Applications/MAMP/htdocs/library/XenForo/Template/Helper/Core.php on line 1154 and defined in /Applications/MAMP/htdocs/library/XenForo/Model/User.php, line 1379
Argument 1 passed to XenForo_Template_Helper_Core::helperIsMemberOf() must be an array, null given in /Applications/MAMP/htdocs/library/XenForo/Template/Helper/Core.php, line 1146
Argument 1 passed to XenForo_Model_User::isMemberOfUserGroup() must be an array, null given, called in /Applications/MAMP/htdocs/library/XenForo/Template/Helper/Core.php on line 1154 and defined in /Applications/MAMP/htdocs/library/XenForo/Model/User.php, line 1379
Argument 1 passed to XenForo_Template_Helper_Core::helperIsMemberOf() must be an array, null given in /Applications/MAMP/htdocs/library/XenForo/Template/Helper/Core.php, line 1146
Argument 1 passed to XenForo_Model_User::isMemberOfUserGroup() must be an array, null given, called in /Applications/MAMP/htdocs/library/XenForo/Template/Helper/Core.php on line 1154 and defined in /Applications/MAMP/htdocs/library/XenForo/Model/User.php, line 1379

Can anyone fix this so it does work, and explain to me how you did it so I can learn? Pretty please...

I would like to be able to use these things without template edits preferably...
 

Attachments

I know I created the even numbered arguments due to using the @ within the template so users can input their own usergroup id per userrank. I understand the odd numbers are being caused by using the xen:helper ismemberoff conditional.

I don't know much about PHP, but I understand that... I think.

I am assuming I have to somehow parse these within the Listener.php I am using to hook into the message_user_info template, but I don't know what should be used or whether a whole new php file is needed.
 
The issue, I guess, is that the $user variable is not sent to the template. I had somethig similar with my mod before.

The solution is to add a FrontControllerPreview class that injects the vairable to the template. If you have XenMoods, it has that approach already. IIRC it uses an initDependencies and a FrontController class to accomplish this.
 
My NodesAsTabs addon has a listener for template_hook that should be helpful here:

Rich (BB code):
	public static function nodeOptions($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
	{
		if (in_array($hookName, array(
			'admin_page_edit_basic_information',
			'forum_edit_basic_information',
			'admin_category_edit',
			'admin_link_forum_edit'
		)))
		{
			// START BY SETTING DEFAULT OPTIONS
			$dw = XenForo_DataWriter::create('NodesAsTabs_DataWriter_Options');
			$natOptions = $dw->getFieldDefaults();

			// THEN POSSIBLY OVERRIDE THEM WITH EXISTING OPTIONS
			$params = $template->getParams();
			if (!empty($params['page']['node_id'])) $nodeId = $params['page']['node_id'];
			if (!empty($params['forum']['node_id'])) $nodeId = $params['forum']['node_id'];
			if (!empty($params['category']['node_id'])) $nodeId = $params['category']['node_id'];
			if (!empty($params['link']['node_id'])) $nodeId = $params['link']['node_id'];
			if (!empty($nodeId))
			{
				$optionsModel = XenForo_Model::create('NodesAsTabs_Model_Options');
				$existing = $optionsModel->getOptionsById($nodeId);
				if (!empty($existing['node_id']))
				{
					$natOptions = $existing;
				}
			}

			$contents .= $template->create('nat_nodeoptions', array(
				'natOptions' => $natOptions
			))->render();
		}
	}

This shows how your template_hook listener can check for the name of the hook (first red block) and then render a template (named nat_nodeoptions in my case) with params defined for use inside of the template (natOptions in my case) and append that rendered template to the contents of the hook.
 
The issue, I guess, is that the $user variable is not sent to the template. I had somethig similar with my mod before.

The solution is to add a FrontControllerPreview class that injects the vairable to the template. If you have XenMoods, it has that approach already. IIRC it uses an initDependencies and a FrontController class to accomplish this.

The template hook he is using (message_user_info_text) actually has $user available to it as you can see in message_user_info:

Code:
	<xen:hook name="message_user_info_text" params="{xen:array 'user={$user}', 'isQuickReply={$isQuickReply}'}">

So you can access $user through $hookParams in your listener. You can pass that as a parameter for the template you are rendering in the listener. My previous post shows how you can render a template with your own parameters defined.
 
Top Bottom