Helper Help? Prefix PhraseText

arms

Well-known member
As I'm learning by creating functionality I need, This modification may seem like a bridge too far to start but making good headway.

What I'm doing is adding another prefix to threads (They will go at end of thread title, so will be called suffixes for now,,.. basically I'm copying the prefix code and rewriting is as suffix.). I've got all the admin side working and works exactly like the standard prefix functionality.

upload_2014-3-3_22-1-28.webp

upload_2014-3-3_22-2-36.webp

I've added the suffix_cache, default_suffix_id & require_suffix to xf_forum.
I've added tables, xf_forum_suffix, xf_thread_suffix_group & xf_thread_suffix that mirror prefix table fields.

I've checked the phrases and when being added phrases are also being updated correctly. the forum.suffix_cache is being populated.

Problem is I can't get the helper to work correctly:

upload_2014-3-3_22-11-32.webp

The phrase is being missed and I'm not sure if it's because my helper is wrong. The group is there and the correct css class for each is there and if I select an option, its recording in the dbase.

I can then do things like index.php?forums/more-main.7/&prefix_id=8&suffix_id=18 which works like I want.

Any real developers (basically anyone better than my half baked non skills) willing to help with this last bit? Have I missed something, is below a load of rubbish?
I've spent a fair bit of time on this and I seem to have spent most of it trying to fix this bit so any help would be appreciated.


Code:
<option value="{$suffix.suffix_id}" data-css="{$suffix.css_class}" {xen:selected '{$selectedSuffix} == {$suffix.suffix_id}'}>{xen:helper threadSuffix, $suffix.suffix_id, escaped, ''}</option>


Proxy.php
PHP:
class PG_Suffix_Listener_Proxy
{
        public static function dependencies(XenForo_Dependencies_Abstract $dependencies, array $data)
    {
      
        XenForo_Template_Helper_Core::$helperCallbacks['threadsuffix'] = array('PG_Suffix_ViewPublic_Helper_Suffix', 'helperThreadSuffix');
        XenForo_Template_Helper_Core::$helperCallbacks['threadsuffixgroup'] = array('PG_Suffix_ViewPublic_Helper_Suffix', 'helperThreadSuffixGroup');
      
        }
}



Suffix.php
PHP:
<?php

class PG_Suffix_ViewPublic_Helper_Suffix
{

    protected static $_language = null;
  
    protected static $_threadSuffixes = array();

    public static function helperThreadSuffixGroup($suffixGroupId)
    {
        return self::_getPhraseText('thread_suffix_group_' . $suffixGroupId);
    }

    /**
     * Helper to display a thread suffix for the specified suffix ID/thread. Can take an array.
     *
     * @param integer|array $suffixId Suffix ID or array with key of suffix_id
     * @param string $outputType Type of output; options are html (marked up), plain (plain text), escaped (plain text escaped)
     * @param string|null $append Value to append if there is a suffix (eg, a space); if null, defaults to space (html) or dash (plain)
     *
     * @return string
     */
    public static function helperThreadSuffix($suffixId, $outputType = 'html', $append = null)
    {
        if (is_array($suffixId))
        {
            if (!isset($suffixId['suffix_id']))
            {
                return '';
            }

            $suffixId = $suffixId['suffix_id'];
        }

        $suffixId = intval($suffixId);
        if (!$suffixId || !isset(self::$_threadSuffixes[$suffixId]))
        {
            return '';
        }

        $text = self::_getPhraseText('thread_suffix_' . $suffixId);
        if ($text === '')
        {
            return '';
        }

        switch ($outputType)
        {
            case 'html':
                $text = '<span class="' . htmlspecialchars(self::$_threadSuffixes[$suffixId]) . '">'
                    . htmlspecialchars($text) . '</span>';
                if ($append === null)
                {
                    $append = ' ';
                }
                break;

            case 'plain':
                break; // ok as is

            default:
                $text = htmlspecialchars($text); // just be safe and escape everything else
        }

        if ($append === null)
        {
            $append = ' - ';
        }

        return $text . $append;
    }

    /**
     * Fetches the text of the specified phrase
     *
     * @param string $phraseName
     *
     * @return string
     */
    protected static function _getPhraseText($phraseName)
    {
        if (self::$_language && isset(self::$_language['phrase_cache']))
        {
            $cache = self::$_language['phrase_cache'];
            return (isset($cache[$phraseName]) ? $cache[$phraseName] : '');
        }
        else
        {
            $phrase = new XenForo_Phrase($phraseName);
            return $phrase->render(false);
        }
    }

    /**
     * Sets the thread suffixes.
     *
     * @param array $suffixes [suffix id] => class name
     */
    public static function setThreadSuffixes($suffixes)
    {
        self::$_threadSuffixes = $suffixes;
    }
 
}
 
Last edited:
In your helperthreadsuffix function change if $text === '') return ''; to return 'test'; and see if that changes them from being blank to being "test". My apologies if this isn't clear, I'm on my phone. My theory though is that your phrase isn't being found.
 
Thanks @Daniel Hood . That's helped. I know where its failing, ( on the if (!$suffixId || !isset(self::$_threadSuffixes[$suffixId])) so just installing PHPStorm so I can debug easier.
 
Thanks for your help @Daniel Hood. I have it working now and works exactly like the prefix function, with click to filter by, (I can filter for prefix of Test and suffix of Cheese) and default values per node etc, caching of phrases etc.

Even worked out how to extend public dependencies.

upload_2014-3-15_19-54-41.webp

upload_2014-3-15_20-5-26.webp
 
As its for personal use, Would you mind if I extended it to multi suffix, using your js. I have your multi prefix add on.
 
You bought the license to use the code how you want. You may not redistribute it though (which you already implied you wouldn't).
 
Top Bottom