Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: slug customization #249

Closed
RVxLab opened this issue Sep 9, 2022 · 2 comments · Fixed by #277
Closed

Proposal: slug customization #249

RVxLab opened this issue Sep 9, 2022 · 2 comments · Fixed by #277

Comments

@RVxLab
Copy link
Collaborator

RVxLab commented Sep 9, 2022

This proposal comes forward from several bug reports, primarily from Chinese users, that slugs don’t work in their resources. #145, #167, among others.

While the workaround is to use the name property which then gets slugged, it’s better to have a more systematic approach. For this I propose to add a static method to the Tab class:

class Tab 
{
    protected static ?Closure $createSlugUsing = null;

    public static function createSlugUsing(Closure $createSlugUsing): void
    {
        self::$createSlugUsing = $createSlugUsing; 
    }
}

The signature of the closure: (Tab $tab): string (could be enforced with a PHPStan or Psalm annotation)

During construction of the slug, the Tab class is checked if the passes closure is set and if so, used. Otherwise it will default to its current behaviour.

The closure can be passed in a service provider:

public function boot(): void
{
    Tab::createSlugUsing(fn (Tab $tab) => Str::slug($tab->getName()));
}
@marcfil
Copy link
Collaborator

marcfil commented Sep 9, 2022

Hi @RVxLab,

Could you turn this into a PR and test it?

@RVxLab
Copy link
Collaborator Author

RVxLab commented Sep 9, 2022

I can turn it into a PR but I can't test it beyond a unit test, I don't have a Nova 4 license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants