Cockpit-HQ / Cockpit

Cockpit Core - Content Platform
https://getcockpit.com
Other
388 stars 47 forks source link

Was the 'slug' option removed from newer versions? #149

Closed ebrenner-code closed 7 months ago

ebrenner-code commented 1 year ago

It seems setting slug: true in the latest version of cockpit has no effect. Was it removed as an option? What is the current suggested method for automatically creating slugs for content?

pozylon commented 1 year ago

Just found about it too, I think it's gone, missing the feature for a customer.

pozylon commented 1 year ago

related: https://github.com/Cockpit-HQ/Cockpit/issues/26

aheinze commented 1 year ago

Hi 👋 this had multiple reasons, as it most of the times needed additional custom implementation.

How to implement a (simple) slug solution:

In your /config/bootstrap.php file (create one if not already existing) add the following code:

<?php

// add slug data to an article collection item
$app->on('content.item.save.before.articles', function(&$data) {

    // add sluggified version of the title field:
    if (isset($data['title']) && $data['title']) {
        $data['title_slug'] = $this->helper('utils')->sluggify(trim($data['title']));
    }

});