raffaelj/cockpit-uniqueslugs

Cockpit CMS v1 中集合条目的唯一 slug

安装: 122

依赖: 3

建议者: 0

安全: 0

星标: 15

关注者: 3

分支: 2

开放问题: 0

类型:cockpit-module

0.5.5 2022-12-16 09:44 UTC

This package is auto-updated.

Last update: 2024-09-16 16:34:06 UTC


README

此插件与 Cockpit CMS v2 不兼容。

另请参阅 Cockpit CMS v1 文档Cockpit CMS v1 仓库 以及 Cockpit CMS v2 文档Cockpit CMS v2 仓库

Cockpit CMS 中的集合唯一 slug

安装

将此仓库复制到 /addons 目录中,并命名为 UniqueSlugs,或者使用 CLI。

通过 git

cd path/to/cockpit
git clone https://github.com/raffaelj/cockpit_UniqueSlugs.git addons/UniqueSlugs

通过 cp CLI

cd path/to/cockpit
./cp install/addon --name UniqueSlugs --url https://github.com/raffaelj/cockpit_UniqueSlugs/archive/master.zip

通过 composer

请确保在您的项目的 composer.json 文件中已定义 cockpit 插件路径。

{
    "name": "my/cockpit-project",
    "extra": {
        "installer-paths": {
            "addons/{$name}": ["type:cockpit-module"]
        }
    }
}
cd path/to/cockpit-root
composer create-project --ignore-platform-reqs aheinze/cockpit .
composer config extra.installer-paths.addons/{\$name} "type:cockpit-module"

composer require --ignore-platform-reqs raffaelj/cockpit-uniqueslugs

使用方法

将这些选项添加到 path/to/cockpit/config/config.php 中,以指定用于生成 slug 的集合和字段名称

<?php

return [
    'app.name' => 'my app',

    // unique slugs
    'unique_slugs' => [
        'collections'    => [
            'pages'      => 'title',
            'products'   => 'name',
        ],
        'localize' => [
            'pages'     => 'title',
            'products'  => 'name',
        ],
    ],

    // ACL example
    'groups' => [
        'manager' => [
            'cockpit' => [
                'backend' => true,
            ],
            'uniqueslugs' => [
                'manage' => true,
            ],
        ],
    ],
];

所有选项

<?php

return [
    'app.name' => 'my app',

    // unique slugs
    'unique_slugs' => [
        'slug_name'      => 'slug', // default: "slug"
        'placeholder'    => 'page', // default: "entry"
        'check_on_update' => true,  // default: false, unique checks on each
                                    // update (if user changes slug by hand)
        'delimiter'      => '|',    // default: "|", is used for nested fields

        'collections'    => [
            'pages'      => 'title',
            'products'   => 'name',
            'something'  => [       // use multiple fields as fallbacks
                'title',
                'name',
                'image|meta|title', // use nested fields for slugs
            ],
        ],
        'localize' => [             // for localized fields, omitted if not set
            'pages'     => 'title', // field name without suffix ("_de")
            'products'  => 'name',
            'something' => [        // use multiple fields as fallbacks
                'title',
                'name',
                'image|meta|title', // use nested fields for slugs
            ],
        ],
    ],

    // ACL example
    'groups' => [
        'manager' => [
            'cockpit' => [
                'backend' => true,
            ],
            'uniqueslugs' => [
                'manage' => true,
            ],
        ],
    ],
];

或者使用 GUI。如果您不是管理员,则您的用户组需要管理权限。

uniqueslugs-gui

注意

配置文件中的硬编码设置将覆盖 GUI 设置。

如果您在某个原因下同时设置了 slug_name: fieldname_slug 和在 fieldname 选项中设置了 {"slug": true},请不要设置 slug_name: fieldname_slug。它应该可以正常工作,但在多语言设置中可能会失败(解释)。

如果需要手动编辑,您的集合可以有一个名为 "slug" 的可见字段。

通过在后台通过选项 {"slug": true} 将文本字段转换为 slug 的内置选项使用 JavaScript。如果您想要唯一的 slug,则此选项不再是必需的。

此插件代码灵感来源于 fabianmu 的 gist

感谢 fabianmuaheinze