XF 1.5 Prefix Phrase from prefix_id

LPH

Well-known member
I'm able to pull the prefix_id for a thread but stuck on how to display the prefix phrase. A var_dump isn't giving any clues.

PHP:
 /** @var XenForo_Model_ThreadPrefix $threadPrefixes */
$threadPrefixes = XenForo_Model::create( 'XenForo_Model_ThreadPrefix' );
$thread_prefix = $threadPrefixes->getPrefixById($prefix_id);

The var_dump doesn't show a phrase or title.

Code:
array (size=6)
  'prefix_id' => int 1
  'prefix_group_id' => int 0
  'display_order' => int 1
  'materialized_order' => int 1
  'css_class' => string 'prefix prefixRed' (length=16)
  'allowed_user_group_ids' => string '-1' (length=2)
 
Last edited:
You may want to call XenForo_Model_ThreadPrefix::preparePrefix(). That will add the phrase entry.
 
You may want to call XenForo_Model_ThreadPrefix::preparePrefix(). That will add the phrase entry.

Thank you. I was looking at this last night and this morning and I'm still chasing my tail. thread_prefix_Blog Entry is in the dump but this seems roundabout. I keep looking at the code where these methods are used and I'm clearly not getting it. Would a trim really be necessary?

PHP:
/** @var XenForo_Model_ThreadPrefix $threadPrefixes */
$threadPrefixes = XenForo_Model::create( 'XenForo_Model_ThreadPrefix' );
$thread_prefix = $threadPrefixes->getPrefixById($prefix_id);

/** @var XenForo_Model_ThreadPrefix $threadPrepare */
$preparePrefix = $threadPrefixes->preparePrefix($thread_prefix);
$prefixTitle = $preparePrefix['title'];

/** @var XenForo_Model_ThreadPrefix $threadPrefixes */
$threadPrefixes = XenForo_Model::create( 'XenForo_Model_ThreadPrefix' );
$thread_prefix_name = $threadPrefixes->getPrefixTitlePhraseName($prefixTitle);
Zend_Debug::dump($thread_prefix_name);
 
In your code, $preparePrefix['title'] is the title itself, not the phrase name.
 
In your code, $preparePrefix['title'] is the title itself, not the phrase name.

A var_dump of $prefixTitle doesn't return the title. It returns the following:

PHP:
object(XenForo_Phrase)[255]
  protected '_phraseName' => string 'thread_prefix_1' (length=15)
  protected '_params' =>
    array (size=0)
      empty
  protected '_insertParamsEscaped' => boolean true
  protected '_phraseNameOnInvalid' => boolean true

I'm sorry to be daft. The code from last night is poorly written with variable names. I'm fixing it right now and will keep tinkering.
 
Last edited:
Echo that or case it to a string -- that's how phrases work in XF. They are objects that will render to the text when needed.
 
Echo that or case it to a string -- that's how phrases work in XF. They are objects that will render to the text when needed.

Thank you. I think this is my misunderstanding and will tinker more tonight.
 
In case someone else trips over this thread, the thread prefix code is easier than my roundabout.

PHP:
/** @var XenForo_Model_ThreadPrefix $prefixModel */
$prefixModel = XenForo_Model::create( 'XenForo_Model_ThreadPrefix' );
$thread_prefix = $prefixModel->getPrefixById($prefix_id);
$preparePrefix = $prefixModel->preparePrefix($thread_prefix);
$prefixTitle = $preparePrefix['title'];

echo $prefixTitle;
 
Last edited:
Back
Top Bottom