XF 2.0 How to properly extend setupThreadCreate

AndyB

Well-known member
I have an add-on called Title control, it's purpose is to make changes to the thread title. The following code is used when a new thread is created.

The code works fine, but don't I need to get the parent, then make needed updates to the creator object then return the parent? Or is the code proper?

PHP:
<?php

namespace Andy\TitleControl\XF\Pub\Controller;

use XF\Mvc\ParameterBag;

class Forum extends XFCP_Forum
{
	protected function setupThreadCreate(\XF\Entity\Forum $forum)
	{
		$title = $this->filter('title', 'str');

		$message = $this->plugin('XF:Editor')->fromInput('message');

		$creator = $this->service('XF:Thread\Creator', $forum);
		
		// get options
		$options = \XF::options();
		
		// get options from Admin CP -> Options -> Title control -> Uppercase first  
		$uppercaseFirst = $options->titleControlUppercaseFirst;
		
		// get options from Admin CP -> Options -> Title control -> External file
		$externalFile = $options->titleControlExternalFile;
		
		// get options from Admin CP -> Options -> Title control -> Multibyte  
		$multibyte = $options->titleControlMultibyte;
		
		// uppercase first
		if ($uppercaseFirst)
		{	
			if ($multibyte)
			{
				// to work with non-latin characters
				$title = mb_strtoupper(mb_substr($title, 0, 1, 'UTF-8'), 'UTF-8') . mb_substr($title, 1, mb_strlen($title), 'UTF-8');
			}
			else
			{
				$title = ucfirst($title);
			}
		}
		
		// include optional external file
		if ($externalFile != '')
		{		
			if (file_exists($externalFile))
			{
				include($externalFile);
			}
		}

		$creator->setContent($title, $message);

		return $creator;
	}
}
 
PHP:
class Forum extends XFCP_Forum
{
    public function setupThreadCreate(\XF\Entity\Forum $forum)
    {
         $creator = parent::setupThreadCreate($forum);
 
Top Bottom