Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Manual slug with Observer_Slug
  • 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.
  • Per docs:

    'property' => 'slug',  // property to set the slug on when empty


    What does the comment mean?
  • The name of the column (the ORM object property) in which the generated slug is saved.
  • When empty? (asking because that's what I wanted to implement, and it looks like it's documented that way)
  • HarroHarro
    Accepted Answer
    Up until 1.7, the slug is always generated, and updates the model property, empty or not.

    As of 1.7.1, the Observer_Slug will have the option to disable overwriting an already existing value.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion