• [deleted]

Hi. I know this has been discussed already previously, but are there any plans to allow the maximum number of characters that the title in each post permits ?

I have some feed items that need longer subject lines, and so need to understand where this is configured so I can increase it. I realise I'm going to be modifying the core here but it's essential.

Any pointers ? Thanks

    [deleted] Do you need this? ↓

    Title Limit

    /vendor/flarum/core/src/Discussion/DiscussionValidator.php
    
    'title' => [
                'max:80'
            ]

    Post Limit

    /vendor/flarum/core/src/Post/PostValidator.php
    
    protected $rules = [
            'content' => [
                'max:65535'
            ]
        ];
      • [deleted]

      clarkwinkelmann Any examples of how to include this in extend.php ?

      /vendor/flarum/core/src/Discussion/DiscussionValidator.php
      
      'title' => [
                  'max:180'
              ]
      • Kylo replied to this.

        [deleted] perhaps something like (based on Clark's code)

        <?php
        
        use Flarum\Extend;
        use Flarum\Foundation\Event\Validating;
        use Flarum\Discussion\DiscussionValidator;
        use Illuminate\Contracts\Events\Dispatcher;
        use Illuminate\Support\Str;
        
        return [
          // Register extenders here
          new Extend\Compat(function(Dispatcher $events) {
            $events->listen(Validating::class, function(Validating $event) {
              if ($event->type instanceof DiscussionValidator) {
                $rules = $event->validator->getRules();
                
                $rules['title'] = array_map(function(string $rule) {
                  if (Str::startsWith($rule, 'max:')) {
                    return 'max:180';
                  }
                  
                  return $rule;
                }, $rules['title']);
        
                $event->validator->setRules($rules);
              }
            });
          }),
        ];
        18 days later
        • [deleted]

        Circling back here, as the code I added to extend.php in the root of Flarum doesn't seem to work. Here's what I am using

        
        <?php
        
        /*
         * This file is part of Flarum.
         *
         * (c) Toby Zerner <toby.zerner@gmail.com>
         *
         * For the full copyright and license information, please view the LICENSE
         * file that was distributed with this source code.
         */
        
        use Flarum\Extend;
        use Flarum\Frontend\Document;
        use Flarum\Foundation\Event\Validating;
        use Flarum\Discussion\DiscussionValidator;
        use Illuminate\Contracts\Events\Dispatcher;
        use Illuminate\Support\Str;
        
        return [
            (new Extend\Frontend('forum'))
                ->content(function (Document $document) {
                $document->meta['theme-color'] = '#12171a';
            })
        ];
        
        return [
          // Register extenders here
          new Extend\Compat(function(Dispatcher $events) {
            $events->listen(Validating::class, function(Validating $event) {
              if ($event->type instanceof DiscussionValidator) {
                $rules = $event->validator->getRules();
                
                $rules['title'] = array_map(function(string $rule) {
                  if (Str::startsWith($rule, 'max:')) {
                    return 'max:180';
                  }
                  
                  return $rule;
                }, $rules['title']);
        
                $event->validator->setRules($rules);
              }
            });
          }),
        ];

        However, when using the API, some inserts are failing as the number of characters in the title exceeds 80. Is there a setting that targets the API specifically ?

        Thanks

          [deleted] a php file can only return once:

          // .. your other stuff before return
          
          return [
              (new Extend\Frontend('forum'))
                  ->content(function (Document $document) {
                  $document->meta['theme-color'] = '#12171a';
              }),
            // Register extenders here
            new Extend\Compat(function(Dispatcher $events) {
              $events->listen(Validating::class, function(Validating $event) {
                if ($event->type instanceof DiscussionValidator) {
                  $rules = $event->validator->getRules();
                  
                  $rules['title'] = array_map(function(string $rule) {
                    if (Str::startsWith($rule, 'max:')) {
                      return 'max:180';
                    }
                    
                    return $rule;
                  }, $rules['title']);
          
                  $event->validator->setRules($rules);
                }
              });
            }),
          ];
          • [deleted]

          @luceos OMG I should have realised that !!
          Thanks

            [deleted] Yeah I just read what I wrote. What I meant is; a php file can obviously have multiple returns, but only the first is being used, code execution halts after.

              8 months later

              [deleted] Can you post the full and final working code you're using?