I'm thinking about a check in Observer_Slug's before_insert() whether the slug was given manually, and only generate a slug, if it isn't. I really see the benefits, since if a CMS user migrates pages manually, or something similar, he/she can specify the slug at the time of adding a page or whatever. Also if the slug field is left blank, a slug is generated.
I think it's a good idea, but I want to make sure that it most probably wouldn't break existing uses of Observer_Slug. What do you think?
Like that, it will definitely break the current functionality, as you intend to alter the logic.
If you want to propose something like this, control it's behaviour via a property (overwrite true/false), with a default of false to mimic the current behaviour.
The observer is meant to generate the slug from other fields in the record. The user should change those fields, not the slug itself.
This way when users upgrade they are not confronted with application issues.
I thought probably nobody would set the slug manually and then expect it to be overwritten, but I'm definitely satisfied with an overwrite option. I understand that when someone updates a row, then it cannot be told whether it was set manually given that manually the same value could be set, but I didn't think about altering the update. If someone wants the slug permanent, the before_update can be omitted from the events. I'm only talking about the before_insert(), and only want the manually set slug persist.
If you insist the implementation to use a property to determine whether it should overwrite empty slugs, it's OK for me as well, but I'm really curious what it could break.
The problem is that on insert, you could get away with "if not empty then skip", but only on the assumption that nobody assigns something manually. If that assumption is false, you break current functionality as the wrong value will be stored.
On update however, the slug always has a value. Say I generate the slug from the 'title' column, and I change the title column AND the slug, how would you determine whether or not I want a new slug generated from the new title?
The only way to do that, is to configure if you want to overwrite the existing slug value or not.