medienbaecker / kirby-modules

Plugin for modular Kirby websites
MIT License
73 stars 7 forks source link

Modules with auto-generated uid/slug #40

Closed mrflix closed 4 months ago

mrflix commented 9 months ago

A client want's to get rid of the slugs input field when creating a module. I think they have a point because as long as we don't use them for in-page hash-navigation (studio-walz.com/#our-team), they're never user-facing. The slug could as well be an auto-generated UUID.

I'm thinking about how to best approach this. I guess I'll need Kirby 4 and I need to hide the slug input via create in the page blueprint. And I need to disable changing the slug:

create:
  title:
    label: Title
options:
  changeSlug: false

Next I'd have to hook into the page creation cycle to set the slug to a generated UUID.

@medienbaecker did you ever attempt this? Do you think it's feasible?

medienbaecker commented 9 months ago

Interestingly enough I did attempt something very similar recently. Unfortunately I did not manage to hide the slug field in the page creation dialog. Somehow that field seems to be hardcoded, you can't even change the type to hidden. I remember I found multiple questions about that in the Discord and Forums. But yeah, if that worked it would be easy to implement it exactly how you described.

mrflix commented 9 months ago

In v4 it's super easy to hide the dialog in the creation dialog 😍

Screenshot 2023-11-29 at 18 09 23

You can't hide it in the title editing dialog but disabling the field does the job that you won't run into problems here:

Screenshot 2023-11-29 at 18 10 16

Do you mind sharing the code you used to inject the uuid?

mrflix commented 9 months ago

Oh wait, no: I did indeed hide the field using CSS 😬

[data-id="default"] .k-dialog-body .k-field-name-slug {
  display: none;
}
medienbaecker commented 9 months ago

I'm afraid I gave up after the slug field disappointment 😬

What I planned was the following: since the UUID is generated after this dialog I wanted to generate a UUID as the value (or default value) of the (invisible) slug field. Then I would have been able to overwrite the UUID method in the page model.

medienbaecker commented 7 months ago

FYI: I just pre-released Kirby Modules 2.7.1 with this feature.