Slug-length longer than 128 characters possible?

Hello,
it seems config’s ‘slugs.maxlength’ can only be used to limit length to less than 128, but not more.

However we are moving from an old page with quite long urls and I would need to allow up to 258 characters.

Is this possible?

Thanks in advance,
Witold

Well, this does not answer my question. I already new the option “maxlength”, as I mentioned in my question. Problem is, how can I make a slug longer than 128, not shorter.

It does not say that you can only shorten the slug.
By entering a value above 120, you can increase the slug length.
I have just tested it and it works perfectly.
Here is an example with 258 characters:

/site/config/config.php

return [
  'slugs.maxlength' => 258
];

If you need help with the configuration of config.php, I will be happy to help you here.

Okay, did absolutely not work for me, I tried several things. Must then be another problem with my configuration, not a general thing with the maxlength-option.
Good to now - thanks a lot.

Problems can be solved. But we need to know the cause.
Have you installed additional plugins?
Can you post the code from your config.php here?

@texnixe Can the length of the slugs only be changed with Kirby 4, or also with Kirby 3?

I’m on 3.9
If I put maxlength to 127 or lower the mentioned warning comes, if I put 128 or higher, no warning, but slug is capped at 128

Excerpt from config

<?php

// Load dotenv class so env() can be used in config file
require_once __DIR__ . '/../plugins/kirby3-dotenv/global.php';

loadenv([
  'dir' => realpath(__DIR__ . '/../../'), // .env files are located in project root
  // Declare strictly required env variables here – an exception will be thrown if missing!
  // 'required' => [
  //   'MY_SECRET'
  // ]
]);

return [
  'debug' => true,
  'loadMarker.io' => false,

  'cache' => [
    'pages' => [
      'active' => false,
      'ignore' => function ($page) {
        $cockpitPage = getPageById(option('page-autoid-cockpit'));
        $ignoredTemplates = ['tp-cockpit', 'tp-cockpit-form'];
        return in_array($page->template()->name(), $ignoredTemplates) || $page->isChildOf($cockpitPage);
      }
    ],
    'shopware' => [
      'active' => true,
    ]
  ],

  'panel' => [
    'install' => true,
    'css' => 'panel.css',
  ],

  'updates' => 'security',

  'markdown' => [
    'extra' => false
  ],

  'slugs' => 'de',
  'slugs.maxlength' => 129,

  'session' => [
    'durationNormal' => 10800, // 3 hours
    'durationLong' => 2419200, // 4 weeks
    'timeout' => 3600, // 1 hour
  ],

  // Language & Locale settings
  'languages' => true,
  'languages.detect' => true,
  'locale' => 'de_DE.utf-8',
  'date.handler'  => 'intl',

I was able to reproduce the behaviour: I have just installed a fresh starterkit with Kirby 3.9. Although I have extended the length of the slugs to 258 characters in config.php, it is shortened to 128 characters. There is also no warning that the slug is too long. In Kirby 4 it works as expected. Perhaps it is a (not yet discovered) error? Therefore, I hope for feedback from @texnixe , if there is another setting for Kirby 3.9.

I finally upgraded to Kirby 4, but the problem still remains.

I then downloaded a fresh starter kit with Kirby 4.
1.) Added
‘slugs.maxlength’ => 258
to config.
2.) created one article.
3.) Changed the slug to a string around 256 chars, it’s immediately cropped to 128 chars

Bildschirmfoto 2024-07-11 um 15.44.32

you could also try this as it was done in the Kirby unittests

return [
  'slugs' => ['maxlength' => false],
];

No difference.
But isn’t the unit-test expecting some exception because 273 is too long?

I also thought that it might be some maxlength-problem on my local system (macos), but the max filename length is 255 and I can create a dir with a few chars shorter

slugs.maxlength only works for setting a shorter slug length than 128, so basically, this is used for validating the slug length. However, when it comes to creating a new page in the Page::create() method, it goes through Str::slug(). This method has a $maxlength parameter, which defaults to 128, when the parameter is not set (and it is not at page creation).

Do you think we should pass the value of slugs. maxlength there (and potentially other places, would need to search through code for other places)? Or is the current behavior correct and we should just mention this in the docs?

If there is no good reason to keep the max length, then we should pass the parameter along where we use Str::slug() in the page slug context (create, duplicate, changeSlug() etc).

I think even more broadly, e.g. field methods, converters named slug also would relate to the option based on the option’s naming, I’d say.

Created an issue: Use `slugs.maxlength` when generating slugs · Issue #6526 · getkirby/kirby · GitHub

Does this mean, we might have a change to work with slugs up to 255 chars in a future version of Kirby?