getkirby-v2 / toolkit

This is the deprecated toolkit for Kirby v2.
http://getkirby.com
81 stars 50 forks source link

Allow '_' as a valid character for str::slug. #91

Closed mzur closed 8 years ago

mzur commented 9 years ago

I'm currently having a discussion with aftereffectsmagic on how to implement the calendar plugin using subpages as events instead of a structure field.

This works really well with one exception: The calendar plugin requires an event to have a _begin_date field (there can be others like _begin_time, too). The _ prefix marks them as immutable fields of the plugin. The snake case format was chosen because the panel converts all keys to lower case.

While this works fine using a structure field containing all events, it breaks when each event should be represented by a subpage. This is because of the str::slug method stripping all page field keys of any character other than a-z0-9, which includes the _.

Since strings containing _ are valid PHP variable names (for page field accessors like $page->_begin_date()) as well as valid URLs, I'm now creating this pull request adding _ to the allowed characters of str:slug to fix this issue.

bastianallgeier commented 8 years ago

Almost 1 year later I'm happy to tell you that this has finally arrived in the develop branch :)

You can now change the default parameters for the slug method like this:

str::$defaults['slug'] = [
  'separator' => '-',
  'allowed' => 'a-z0-9_'
];

I will probably also add this as official kirby options.