简体   繁体   English

是否可以仅针对特定文件类型或TYPO3中特定子文件夹中的文件显示自定义sys_file_metadata?

[英]Is it possible to display custom sys_file_metadata only for specific file types or for files inside a specific subfolder in TYPO3?

I am working on a file list extension and want to know if I can set additional meta data only for specific file types like pdf or for all files within a specific subfolder. 我正在研究文件列表扩展名,想知道我是否只能为pdf等特定文件类型或特定子文件夹中的所有文件设置其他元数据。

So far I have extended the sys_file_metadata with the following setup: 到目前为止,我已经使用以下设置扩展了sys_file_metadata:

ext_tables.sql ext_tables.sql

CREATE TABLE sys_file_metadata (
    tags int(11) unsigned DEFAULT '0' NOT NULL,
    type int(11) unsigned DEFAULT '0'
);

CREATE TABLE sys_file_metadata_tags_mm (
    uid_local int(11) unsigned DEFAULT '0' NOT NULL,
    uid_foreign int(11) unsigned DEFAULT '0' NOT NULL,
    sorting int(11) unsigned DEFAULT '0' NOT NULL,
    sorting_foreign int(11) unsigned DEFAULT '0' NOT NULL,

    KEY uid_local (uid_local),
    KEY uid_foreign (uid_foreign)
);

sys_file_metadata.php sys_file_metadata.php

<?php
defined('TYPO3_MODE') || die();

$l1 = 'LLL:EXT:file_portal/Resources/Private/Language/locallang_db.xlf:';

$additionalColumns = [
    'tags' => [
        'exclude' => 1,
        'label' => $l1 . 'tx_fileportal_domain_model_file.tags',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectMultipleSideBySide',
            'foreign_table' => 'tx_fileportal_domain_model_tag',
            'MM' => 'tx_fileportal_fileallocation_tag_mm',
            'size' => 10,
            'autoSizeMax' => 30,
            'maxitems' => 9999,
            'multiple' => 0,
            'wizards' => [
                '_PADDING' => 1,
                '_VERTICAL' => 1,
                'edit' => [
                    'module' => [
                        'name' => 'wizard_edit',
                    ],
                    'type' => 'popup',
                    'title' => 'Edit',
                    'icon' => 'edit2.gif',
                    'popup_onlyOpenIfSelected' => 1,
                    'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
                ],
                'add' => [
                    'module' => [
                        'name' => 'wizard_add',
                    ],
                    'type' => 'script',
                    'title' => 'Create new',
                    'icon' => 'add.gif',
                    'params' => [
                        'table' => 'tx_fileportal_domain_model_tag',
                        'pid' => '###CURRENT_PID###',
                        'setValue' => 'prepend'
                    ],
                ],
            ],
        ],
    ],
    'type' => [
        'exclude' => 1,
        'label' => $l1 . 'tx_fileportal_domain_model_file.type',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectSingle',
            'foreign_table' => 'tx_fileportal_domain_model_filetype',
            'minitems' => 0,
            'maxitems' => 1,
            'items' => [
                ['Bitte wählen', 0]
            ],
            'appearance' => [
                'collapseAll' => 0,
                'levelLinksPosition' => 'top',
                'showSynchronizationLink' => 1,
                'showPossibleLocalizationRecords' => 1,
                'showAllLocalizationLink' => 1
            ]
        ]
    ]
];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file_metadata', $additionalColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file_metadata', 'tags, type');

return $GLOBALS['TCA']['sys_file_metadata'];

This is working great and I can add some custom tags and a custom more specific type for my files, but this options are available for all my files now. 这很好用,我可以为文件添加一些自定义标签和自定义更特定的类型,但是此选项现在适用于我的所有文件。 Is there a way to display this options only for specific file types or for files within a specific subfolder, maybe with display conditions? 是否有一种方法可以仅针对特定文件类型或特定子文件夹中的文件(可能具有显示条件)显示此选项?

You can do that with displayCond in the TCA. 您可以使用TCA中的displayCond做到这一点。 Check the documentation . 检查文档

If you want to depend on some field, that field should be added to the requestUpdate option in the ctrl section in the TCA of the table. 如果要依赖某个字段,则应将该字段添加到表的TCA中ctrl部分的requestUpdate选项中。 Check the documentation 检查文件

Now if the value of that field is changed, you're asked to reload the form as the fields may change. 现在,如果该字段的值更改了,由于字段可能会更改,您将被要求重新加载表单。

I don't know how to add a "requestUpdate" to the TCA of sys_file_metadata, because the ExtensionManagementUtility don't contain something like this or am I wrong? 我不知道如何在sys_file_metadata的TCA中添加“ requestUpdate”,因为ExtensionManagementUtility不包含此类内容,或者我错了吗? Display conditions works so far for me and here is my example with conditions for the sake of completeness: 到目前为止,显示条件对我仍然有效,这是我为完整起见使用示例的条件:

<?php
defined('TYPO3_MODE') || die();

$l1 = 'LLL:EXT:file_portal/Resources/Private/Language/locallang_db.xlf:';

$additionalColumns = [
    'downloadable' => [
        'exclude' => 1,
        'label' => $l1. 'tx_fileportal_domain_model_file.downloadable',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectSingle',
            'items' => [
                ['No', 0],
                ['Yes', 1],
            ],
            'minitems' => 0,
            'maxitems' => 1
        ]
    ],
    'tags' => [
        'displayCond' => 'FIELD:downloadable:>:0',
        'exclude' => 1,
        'label' => $l1 . 'tx_fileportal_domain_model_file.tags',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectMultipleSideBySide',
            'foreign_table' => 'tx_fileportal_domain_model_tag',
            'MM' => 'sys_file_metadata_tag_mm',
            'size' => 10,
            'autoSizeMax' => 30,
            'maxitems' => 9999,
            'multiple' => 0,
            'wizards' => [
                '_PADDING' => 1,
                '_VERTICAL' => 1,
                'edit' => [
                    'module' => [
                        'name' => 'wizard_edit',
                    ],
                    'type' => 'popup',
                    'title' => 'Edit',
                    'icon' => 'edit2.gif',
                    'popup_onlyOpenIfSelected' => 1,
                    'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
                ],
                'add' => [
                    'module' => [
                        'name' => 'wizard_add',
                    ],
                    'type' => 'script',
                    'title' => 'Create new',
                    'icon' => 'add.gif',
                    'params' => [
                        'table' => 'tx_fileportal_domain_model_tag',
                        'pid' => '###CURRENT_PID###',
                        'setValue' => 'prepend'
                    ],
                ],
            ],
        ],
    ],
    'type' => [
        'displayCond' => 'FIELD:downloadable:>:0',
        'exclude' => 1,
        'label' => $l1 . 'tx_fileportal_domain_model_file.type',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectSingle',
            'foreign_table' => 'tx_fileportal_domain_model_filetype',
            'minitems' => 0,
            'maxitems' => 1,
            'items' => [
                ['Choose', 0]
            ],
            'appearance' => [
                'collapseAll' => 0,
                'levelLinksPosition' => 'top',
                'showSynchronizationLink' => 1,
                'showPossibleLocalizationRecords' => 1,
                'showAllLocalizationLink' => 1
            ]
        ]
    ],
];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file_metadata', $additionalColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
    'sys_file_metadata', 'downloadable, tags, type'
);

return $GLOBALS['TCA']['sys_file_metadata'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM