Ozzy47
Well-known member
Trying to extend
XF\ThreadType\Article
to add settings for max characters, images and media. Settings are in place. Now If I set the XF setting messageMaxLength
to a value of say 100, and my setting to a value of 150000 then trying to post an article less than 150000 characters, I get the following error message, The submitted message is too long to be processed. Please shorten it.
Im sure there is a problem with the way I am trying to extend the function.
PHP:
<?php
namespace OzzModz\ArticleEnhance\XF\ThreadType;
use XF\Entity\Post;
use XF\Entity\Thread;
use XF\Http\Request;
use XF\Mvc\Entity\Entity as Entity;
/**
* Class Article
*
* Extends \XF\ThreadType\Article
*
* @package OzzModz\ArticleEnhance\XF\ThreadType
*/
class Article extends XFCP_Article
{
public function setupMessagePreparer(
Thread $thread,
Post $post,
\XF\Service\Message\Preparer $preparer
)
{
$parent = parent::setupMessagePreparer($thread, $post, $preparer);
// Get options
$options = \XF::options();
// Get variables
$character = $options->ozzmodzArticlemessageMaxLength;
$images = $options->ozzmodzArticlemessageMaxImages;
$media = $options->ozzmodzArticlemessageMaxMedia;
if (!$post->isFirstPost())
{
return;
}
// articles are significant content, so give them more relaxed constraints than an average post
//$relaxFactor = 3;
//$character = intval($preparer->getConstraint('character'));
if ($character > 0)
{
//$preparer->setConstraint('maxLength', $relaxFactor * $maxLength);
$preparer->setConstraint('maxLength', $character);
}
//$maxImages = intval($preparer->getConstraint('maxImages'));
if ($images > 0)
{
//$preparer->setConstraint('maxImages', $relaxFactor * $maxImages);
$preparer->setConstraint('maxImages', $images);
}
//$maxMedia = intval($preparer->getConstraint('maxMedia'));
if ($media > 0)
{
//$preparer->setConstraint('maxMedia', $relaxFactor * $maxMedia);
$preparer->setConstraint('maxMedia', $media);
}
return $parent;
}
}