ichhabrecht/t3tags

为每种记录类型生成标签字段

安装次数: 1,136

依赖项: 0

建议者: 0

安全: 0

星标: 3

关注者: 3

分支: 5

开放问题: 2

类型:typo3-cms-extension

1.0.1 2020-09-30 11:11 UTC

This package is auto-updated.

Last update: 2024-09-06 06:05:12 UTC


README

Latest Stable Version Build Status StyleCI

为每种记录类型生成标签字段。

功能

  • 集成到核心API并扩展group字段行为
  • 新标签可以动态添加,并且只有当记录被保存时才会创建
  • 添加到多个(标签)字段的新标签只在数据库中创建一次

安装

  1. 只需使用Composer或扩展管理器安装扩展。

composer require ichhabrecht/t3tags

  1. 在扩展设置中配置一个页面UID,其中标签应被存储。

使用方法

使用TagRegistry注册新字段

  • 在Configuration/TCA/Overrides中添加或扩展文件
<?php
defined('TYPO3_MODE') || die();

(function () {
    $tagRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\IchHabRecht\T3tags\Configuration\TagRegistry::class);

    $tagRegistry->makeTaggable(
        'tt_content',
        'relevant_tags',
        [
            'label' => 'Relevant tags',
            'position' => 'after:--palette--;;access',
            'fieldConfiguration' => [
                'maxitems' => 5,
                'fieldInformation' => [
                    'tagInformation' => [
                        'options' => [
                            'labels' => [
                                0 => [
                                    'label' => 'Add here up to five super relevant tags',
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ]
    );

    $tagRegistry->makeTaggable(
        'tt_content',
        'content_tags',
        [
            'label' => 'Content tags',
            'position' => 'after:relevant_tags',
            'fieldConfiguration' => [
                'fieldInformation' => [
                    'tagInformation' => [
                        'options' => [
                            'labels' => [
                                0 => [
                                    'label' => 'Add here unlimited content tags that describe your topic and the content detail',
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ]
    );
})();

参数

  1. 表名:应扩展的现有TCA表
  2. 字段名:要添加的新标签字段名称
  3. 选项:根据TCA字段配置的附加字段配置
    • 标签
    • 排除
    • fieldConfiguration (config)
    • l10n_display
    • l10n_mode
    • displayCond
    • 位置
    • 接口
    • fieldList
    • typesList
  4. 覆盖:如果应使用提供的配置替换任何现有字段配置,则设置为True

通过字段获取所有标签

$tagRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\IchHabRecht\T3tags\Domain\Repository\TagRepository::class);
$tagRepository->findTagsByField('tt_content', 'relevant_tags', 42);
  • 从UID为42tt_content元素及其字段relevant_tags获取所有标签(作为数组)

通过记录获取所有标签

$tagRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\IchHabRecht\T3tags\Domain\Repository\TagRepository::class);
$tagRepository->findTagsByRecord('tt_content', 42);
  • 从UID为42tt_content元素获取所有标签(作为数组)。根据上面的示例注册,返回relevant_tagscontent_tags中的标签。