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

Link a preference to an addon?

Discussion in 'XenForo Development Discussions' started by Jaxel, Dec 27, 2012.

  1. Jaxel

    Jaxel Well-Known Member

    I would like to add some preference options to /account/preferences...

    I know I can do this with account Custom User Fields in the admin CP. But those custom fields are not linked to a specific addon. Is there a way to link preferences to addons?
     
  2. tenants

    tenants Well-Known Member

    I might have misunderstood, do you mean you want options to be added to the /account/preference but without using "Custom User Fields" like :


    account.png
     
  3. tenants

    tenants Well-Known Member

    This can be done with template hooks:

    Code:
        public static function templateHook($name, &$contents, array $params, XenForo_Template_Abstract $template)
        {
            $globalParams = $template->getParams();   
            if ($globalParams['visitor']['permissions']['XenLoginSecurity']['canUseLoginSecurity'] == true)
            {
                switch ($name)
                {
                    case 'account_wrapper_sidebar_settings':
                        $contents .= $template->create('xlsec_account_sidebar_link', $globalParams);
                    break;
                    case 'navigation_visitor_tab_links1':
                        $contents .= $template->create('xls_navigation_visitor_tab_links1', $globalParams);
                    break;
                }
            }
    In my case, the templates look like this:

    xls_navigation_visitor_tab_links1
    Code:
    <li>
        <a class="primaryContent" href="{xen:link login-security/settings}">
            {xen:phrase xlsec_login_security}
        </a>
    </li>

    xlsec_account_sidebar_link
    Code:
    <li>
        <a class="primaryContent" href="{xen:link login-security/settings}">
            {xen:phrase xlsec_login_security}
        </a>
    </li>
     
    Jake Bunce likes this.
  4. James

    James Well-Known Member

    No, he wants to add a new preference (form field) that links to his add-on.

    He can accomplish this with custom user fields, but you cannot assign them to a particular add-on so it's not ideal.
     
    Jake Bunce likes this.
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You mean similar to templates and phrases? Where the object is assigned to your addon id and is included in the XML file? User prefs don't have an object like that, so the answer is no. You need to manually manage the creation and deletion of the preference in your install / uninstall routines. A custom user field is one existing structure you can use. Or you could extend the user record.
     
  6. Jaxel

    Jaxel Well-Known Member

    Thanks Jake... I did it by extending the account controller...

    Browsing Preferences   8WAYRUN.COM   Soulcalibur.png
     

Share This Page