clarkwinkelmann Thank you for your reply..
I have problems with the 2 codes below:
CODE A: Works fine. But counting characters is not accurate.
(new Extend\Validator(\Flarum\Post\PostValidator::class))
->configure(function ($flarumValidator, $validator) {
$rules = $validator->getRules();
// Not all attributes are validated every time. Skip if content is not being validated
if (!array_key_exists('content', $rules)) {
return;
}
$rules['content'][] = 'min:30';
$rules['content'] = array_map(function(string $rule) {
if (\Illuminate\Support\Str::startsWith($rule, 'max:')) {
return 'max:20000';
}
return $rule;
}, $rules['content']);
$validator->setRules($rules);
}),
CODE B: getting error when replying with empty content:
code b: counts the exact number of characters
Error: flarum.ERROR: TypeError: Flarum\Mentions\Formatter\UnparsePostMentions::__invoke(): Argument #2 ($xml) must be of type string, null given, called line 34
/flarum.ERROR: TypeError: Flarum\Mentions\Formatter\UnparsePostMentions::__invoke(): Argument #2 ($xml) must be of type string, null given, called in /public_html/vendor/flarum/core/src/Foundation/ContainerUtil.php on line 30 and defined in /public_html/vendor/flarum/mentions/src/Formatter/UnparsePostMentions.php:36
//flarum.ERROR: TypeError: Flarum\Mentions\Formatter\UnparsePostMentions:: __invoke(): Argument #2 ($xml) must be of type string, null given, called in /public_html/vendor/flarum/mentions/src/Formatter/UnparsePostMentions.php on line 36 and defined in /public_html/vendor/flarum/mentions/src/Formatter/UnparsePostMentions.php:49
//flarum.ERROR: TypeError: Flarum\Mentions\Formatter\UnparsePostMentions::updatePostMentionTags(): Argument #2 ($xml) must be of type string, null given, called in /public_html/vendor/flarum/mentions/src/Formatter/UnparsePostMentions.php on line 36 and defined in /public_html/vendor/flarum/mentions/src/Formatter/UnparsePostMentions.php:49
//flarum.ERROR: TypeError: Flarum\Mentions\Formatter\UnparsePostMentions::unparsePostMentionTags(): Argument #1 ($xml) must be of type string, null given, called in /public_html/vendor/flarum/mentions/src/Formatter/UnparsePostMentions.php on line 37 and defined in /public_html/vendor/flarum/mentions/src/Formatter/UnparsePostMentions.php:81
(new Extend\Event)
->listen(\Flarum\Post\Event\Saving::class, function ($event) {
// Exclude enforcement for administrator and moderator groups
$user = $event->actor;
if ($user instanceof \Flarum\User\User && ($user->isAdmin())) { //|| $user->isModerator())
//return;
}
if ($event->post->isDirty('content')) {
resolve(\Illuminate\Contracts\Validation\Factory::class)->make([
'content' => $event->post->content,
], [
'content' => 'min:20|max:20000',
])->validate();
}
}),
disable flarum-mention plugin: code B Works fine.
To use code B or To use the code below, to count characters correctly, I had to edit the files: and enable flarum-mentions plugin
/public_html/vendor/flarum/mentions/src/Formatter/
UnparsePostMentions.php
line 34 public function __invoke($context, $xml): ?string
line 49 protected function updatePostMentionTags($context, $xml): ?string
line 81 protected function unparsePostMentionTags($xml): ?string
line 85 if (@strpos($xml, $tagName) === false) {
UnparseTagMentions.php
line 25 public function __invoke($context, $xml): ?string
line 40 protected function updateTagMentionTags($context, $xml): ?string
line 63 protected function unparseTagMentionTags($xml): ?string
line 67 if (@strpos($xml, $tagName) === false) {
UnparseUserMentions.php
line 36 public function __invoke($context, $xml): ?string
line 51 protected function updateUserMentionTags($context, $xml): ?string
line 78 protected function unparseUserMentionTags($xml): ?string
line 82 if (@strpos($xml, $tagName) === false) {