首页 文章

如何在Typo3中为上传的文件添加发布日期?

提问于
浏览
2

我目前正在维护一个客户现有的Typo3 6.1网站,他们想要添加到他们网站的一件事就是可以在上传的文件上应用发布和过期日期,就像在Typo3页面上应用这些日期一样 .

我做了一些关于此事的研究,看看之前是否已经完成了这样的事情 . 我试图在谷歌和官方Typo3扩展存储库上寻找现有的Typo3扩展,它将添加此功能,但似乎并不存在这样的东西 . 我也试图找到自己做的方法,仍然没有任何结果 .

将此功能添加到Typo3 6.1网站的最佳方法是什么?

EDIT

经过一番调查,我注意到另一个扩展已经与文件编辑页面的TCEForm连接:http://i.stack.imgur.com/up7mO.png

在此屏幕截图中,您可以看到我设法将开始和结束日期时间字段添加为表单中的前两个字段("Date de publication"和"Date d'expiration") . 我目前在_1263785中有以下配置:

<?php

if (!defined('TYPO3_MODE')) {
    die('Access denied.');
}

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
        $_EXTKEY, 'Documents', 'Documents'
);

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Documents');

\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_file');
$newFileColumns = array(
    'date_publication' => array(
        'exclude' => 0,
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.date_publication',
        'config' => array(
            'type' => 'input',
            'size' => 13,
            'max' => 20,
            'eval' => 'datetime',
            'checkbox' => 0,
            'default' => 0,
            'range' => array(
                'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
            ),
        ),
    ),
    'date_expiration' => array(
        'exclude' => 0,
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.date_expiration',
        'config' => array(
            'type' => 'input',
            'size' => 13,
            'max' => 20,
            'eval' => 'datetime',
            'checkbox' => 0,
            'default' => 0,
            'range' => array(
                'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
            ),
        ),
    ),
    'desactive' => array(
        'exclude' => 1,
        'config' => array(
          'type' => 'passthrough'
        )
    ),
    'isbn' => array(
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.isbn',
        'config' => array(
            'type' => 'input',
            'size' => 50,
            'eval' => 'trim'
        ),
    ),
    'auteurs_internes' => array(
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.auteurs_internes',
        'config' => array(
            'type' => 'select',
            'foreign_table' => 'fe_users',
            'MM' => 'tx_documents_document_auteur_mm',
            'size' => 5,
            'maxitems' => 10,
            'minitems' => 0,
            'wizards' => array(
                'suggest' => array(
                    'type' => 'suggest',
                    'default' => array(
                        'searchWholePhrase' => 1
                    ),
                ),
            ),
        ),
    ),
    'auteurs_externes' => array(
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.auteurs_externes',
        'config' => array(
            'type' => 'input',
            'size' => 50,
            'eval' => 'trim'
        ),
    ),
    'responsable' => array(
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.responsable',
        'config' => array(
            'type' => 'group',
            'internal_type' => 'db',
            'allowed' => 'tx_common_domain_model_unitelogique',
            'size' => 1,
            'maxitems' => 1,
            'minitems' => 0,
            'wizards' => array(
                'suggest' => array(
                    'type' => 'suggest',
                    'default' => array(
                        'searchWholePhrase' => 1
                    ),
                ),
            ),
        ),
    ),
    'type_document' => array(
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.type_document',
        'config' => array(
            'type' => 'select',
            'foreign_table' => 'sys_category',
            'foreign_table_where' => ' AND sys_category.tx_common_type = "type_document" ORDER BY sys_category.title ASC',
            'maxitems' => 1,
            'minitems' => 1,
            'renderMode' => 'tree',
            'treeConfig' => array(
                'parentField' => 'parent',
            ),
        ),
    ),
    'public_cible' => array(
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.public_cible',
        'config' => array(
            'type' => 'select',
            'foreign_table' => 'sys_category',
            'MM' => 'tx_documents_document_publiccible_mm',
            'foreign_table_where' => ' AND sys_category.tx_common_type = "public_cible_document" ORDER BY sys_category.title ASC',
            'maxitems' => 100,
            'minitems' => 0,
            'renderMode' => 'tree',
            'treeConfig' => array(
                'parentField' => 'parent',
            ),
        ),
    ),
    'important' => array(
        'exclude' => 1,
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.important',
        'config' => array(
            'type' => 'check',
        ),
    ),
    'nouveau' => array(
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.nouveau',
        'config' => array(
            'type' => 'input',
            'eval' => 'date'
        ),
    ),
    'misajour' => array(
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.misajour',
        'config' => array(
            'type' => 'check',
        ),
    ),
    'no_magistra' => array(
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.no_magistra',
        'config' => array(
            'type' => 'input',
            'size' => 50,
            'eval' => 'trim'
        ),
    ),
    'centre_documentation' => array(
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.centre_documentation',
        'config' => array(
            'type' => 'check',
        ),
    ),
    'image' => array(
        'exclude' => 0,
        'label' => 'LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.image',
        'config' => array(
            'type' => 'group',
            'internal_type' => 'file',
            'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
            'minitems' => 0,
            'maxitems' => 1,
            'size' => 1,
            'show_thumbs' => 1,
            'uploadfolder' => 'uploads/pics',
            'disable_controls' => 'list',
        ),
    ),
);

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file', $newFileColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file', '--div--;LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:document.tab, date_publication, date_expiration, isbn, auteurs_internes, auteurs_externes, responsable, type_document, public_cible, important, nouveau, no_magistra, centre_documentation, image');

// Edit of existing fields
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_file');
$TCA['sys_file']['columns']['title']['config']['placeholder'] = '';
$TCA['sys_file']['columns']['title']['config']['eval'] = 'required';
$TCA['sys_file']['columns']['title']['config']['size'] = '50';

$TCA['sys_file']['columns']['description']['config']['wizards'] = array(
    'RTE' => array(
        'icon' => 'wizard_rte2.gif',
        'notNewRecords' => 1,
        'RTEonly' => 1,
        'script' => 'wizard_rte.php',
        'title' => 'LLL:EXT:cms/locallang_ttc.xlf:bodytext.W.RTE',
        'type' => 'script'
    )
);
$TCA['sys_file']['columns']['description']['defaultExtras'] = 'richtext:rte_transform[flag=rte_enabled|mode=ts]';

// Add category types
\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_category');
$TCA['sys_category']['columns']['tx_common_type']['config']['items'][] = array('LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:category.type.type_document', 'type_document');
$TCA['sys_category']['columns']['tx_common_type']['config']['items'][] = array('LLL:EXT:the_extension_key/Resources/Private/Language/locallang_db.xlf:category.type.public_cible_document', 'public_cible_document');
?>

但是,将列定义为开始和结束访问日期

$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['starttime'] = 'tx_myext_starttime';
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['endtime'] = 'tx_myext_starttime';

如答案中所建议的那样,文件列表显示错误而不是加载文件列表 . 相反,我尝试使用$ TCA变量来定义它们 . Typo3显示的错误页面不再显示使用此功能,但编辑页面仍无法成功呈现 .

我添加的$ TCA配置:

$TCA['sys_file'] = array(
    'ctrl' => array(
        'label' => 'title',
        'label_alt' => 'name,description,alternative,identifier,uid',
        'tstamp' => 'tstamp',
        'crdate' => 'crdate',
        'cruser_id' => 'cruser_id',
        'versioningWS' => 2,
        'versioning_followPages' => TRUE,
        'origUid' => 't3_origuid',
        'enablecolumns' => array(
            'disabled' => 'desactive',
            'starttime' => 'date_publication',
            'endtime' => 'date_expiration',
        )
    )
);

下图显示了在尝试编辑文件时添加的$ TCA配置会发生什么:http://i.stack.imgur.com/8VaCD.png

TCEForm根本没有渲染,我不确定 ext_tables.php 中的配置是否包含错误的配置(特别是在我添加的$ TCA配置中)或者问题是否来自扩展中的另一个文件 .

什么可能导致此错误,我该如何解决?

1 回答

  • 2

    FAL(文件抽象层)没有 starttimeendtime 字段 .

    但由于 sys_file 相关表(如 sys_file_reference )可以通过您自己的扩展进行扩展,而TCA默认为您提供 starttime / endtime 功能,我最大的猜测是可以通过TCA中的一些修改来实现 .

    这里有一个快速启动,介绍如何尝试使用 starttimeendtime 字段扩展 sys_file .

    ext_emconf.php

    $EM_CONF[$_EXTKEY] = array (
        // more stuff here in between
        'constraints' => array (
            'depends' => array (
                'filelist' => '6.1.0-6.1.99',
            ),
        ),
    );
    

    ext_tables.sql

    #
    # Table structure for table 'sys_file'
    #
    CREATE TABLE sys_file (
        tx_myext_starttime int(11) unsigned DEFAULT '0' NOT NULL,
        tx_myext_endtime int(11) unsigned DEFAULT '0' NOT NULL,
    )
    

    ext_tables.php

    <?php
    if (!defined ('TYPO3_MODE')) {
        die ('Access denied.');
    }
    
    $tempColumns = array();
    $tempColumns['tx_myext_starttime'] = array(
        'exclude' => 1,
        'l10n_mode' => 'mergeIfNotBlank',
        'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.starttime',
        'config' => array(
            'type' => 'input',
            'size' => 13,
            'max' => 20,
            'eval' => 'datetime',
            'checkbox' => 0,
            'default' => 0,
            'range' => array(
                'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
            ),
        ),
    );
    
    $tempColumns['tx_myext_endtime'] = array(
        'exclude' => 1,
        'l10n_mode' => 'mergeIfNotBlank',
        'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.endtime',
        'config' => array(
            'type' => 'input',
            'size' => 13,
            'max' => 20,
            'eval' => 'datetime',
            'checkbox' => 0,
            'default' => 0,
            'range' => array(
                'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
            ),
        ),
    );
    
    $GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['starttime'] = 'tx_myext_starttime';
    $GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['endtime'] = 'tx_myext_starttime';
    
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file', $tempColumns, 1);
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sys_file', '--div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access, tx_myext_starttime, tx_myext_endtime');
    unset($tempColumns);
    

    我不知道FAL持久层和存储库是否支持(或更好地:吃掉)这种配置,我无法估计你将遇到哪种问题 . 但我想这是值得尝试的 .

    祝好运!

相关问题