webcoast/editable-menus

菜单编辑器可以轻松在后台更改

安装: 194

依赖项: 0

建议者: 0

安全性: 0

星星: 1

关注者: 0

分支: 0

开放问题: 0

类型:typo3-cms-extension

v1.0.2 2024-02-02 11:20 UTC

This package is auto-updated.

Last update: 2024-08-31 00:28:10 UTC


README

TYPO3 CMS 扩展,可创建独立于页面树/主菜单的菜单,编辑器可以通过选择要在菜单中显示的页面来更改菜单项。

安装

composer req webcoast/editable-menus

配置

此扩展会检查所有活动包中的 Configuration/Menus.php 文件。要正确确定扩展键,必须存在 composer.json 文件,并包含 extra.typo3/cms.extension-key 属性。

该文件必须返回一个包含有效菜单配置的数组

<?php

return [
    'the_menu_identifier' => [
        // The menu configuration
    ],
    // ... more menu configurations
];

注意:建议使用蛇形命名法(小写字母加下划线)来表示菜单标识符,以便在菜单处理过程中的多个地方正常工作。

最小配置

最小菜单配置只是一个空数组

<?php

return [
    'header' => [], // This creates a field called `header_menu` in the root page properties
];

完整配置

<?php

return [
    'header' => [
        'label' => 'My menu label', // Explicitly define a label, can also be a LLL reference
        'description' => 'A description explaining the usage of this menu', // Explicitly define a description, can also be a LLL reference
        'exclude' => false, // Do not make the menu field an exclude field, defaults to true if not defined (null)
        'displayCond' => 'FIELD:is_siteroot:=:1', // Define the display condition of this field. Supports all valid displayCond values. Defaults to `FIELD:is_siteroot:=:1`
        'levels' => 2, // Number of levels for the menu rendering in TypoScript. Defaults to `1`
        'disabled' => true, // Defaults to false, used to disable previously defined menus
    ],
];

覆盖现有菜单

可以覆盖现有菜单以更改其配置或禁用它们。

要这样做,只需使用相同的菜单标识符。配置将使用 array_replace_recursive 合并。

<?php

return [
    'header' => [
        // Add custom label and description for field `header_menu`
        'label' => 'LLL:EXT:sitepackage/Resources/Private/Language/Menus.xlf:header.label',
        'description' => 'LLL:EXT:sitepackage/Resources/Private/Language/Menus.xlf:header.description',
    ],
    'footer' => [
        // Disable the footer menu, meaning the field is not shown in the backend and the SQL for the database column would not be generated
        'disabled' => true,
    ],
];

使用方法

后台界面

对于每个配置的菜单,都会在“菜单设置”选项卡下添加一个字段到网站根属性。

默认情况下,字段作为排除字段添加,编辑器需要显式权限才能查看它。这可以针对每个菜单单独禁用。

菜单字段的名称是通过在菜单标识符后附加 _menu 生成的

  • header 变为 header_menu
  • footer_lower 变为 footer_lower_menu

标签和描述如果未显式设置,将自动确定,通过构建 LLL 引用

  • LLL:EXT:{ext-key}/Resources/Private/Language/Menus.xlf:{menu-identifier}.label
  • LLL:EXT:{ext-key}/Resources/Private/Language/Menus.xlf:{menu-identifier}.description 其中 {ext-key} 是原始定义菜单的扩展的扩展键,而 {menu-identifier} 是菜单标识符,如 headerfooter_lower

Fluid 页面模板 - 数据处理

为每个配置的菜单自动添加 TypoScript 数据处理配置。在 Fluid 模板中保存菜单数据的变量由标识符生成,通过将 snake_case 转换为 UpperCamelCase 并在其前面添加 menu 来生成

  • 标识符 header 在 Fluid 模板中变为 menuHeader
  • 标识符 footer_lower 变为 menuFooterLower

默认 TypoScript 应该对大多数用例足够。然而,您可以通过自己的 TypoScript 覆盖它,如果需要,例如添加子数据处理器。

SQL

为所有配置的菜单生成所有必要的 SQL 以更新数据库,将在下一次数据库比较/模式更新时显示/执行。