Skip to content
This repository was archived by the owner on Jan 25, 2021. It is now read-only.

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

Closed
mzur wants to merge 1 commit intogetkirby-v2:developfrom
mzur:develop
Closed

Allow '_' as a valid character for str::slug.#91
mzur wants to merge 1 commit intogetkirby-v2:developfrom
mzur:develop

Conversation

@mzur
Copy link
Copy Markdown
Contributor

@mzur mzur commented May 29, 2015

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
Copy link
Copy Markdown
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants