Reputation: 63
I am currently maintaining a client's existing Typo3 6.1 site and one of the things they would like to add to their site is the possibility of applying publish and expiration dates on uploaded files, in the same way such dates can be applied on Typo3 pages.
I did some research on the matter to see if something like this had already been done before. I tried looking for existing Typo3 extensions on Google and on the official Typo3 extensions repository that would add this functionality, but nothing like this seems to exist. I also tried to find ways of doing it myself, still without any results.
What would be the best approach to add this functionality to a Typo3 6.1 website?
EDIT
After some investigating, I noticed another extension was already hooked up with the TCEForm of the file editing page: https://i.sstatic.net/up7mO.png
In this screenshot, you can see I managed to add the start and end datetime fields as the first two fields in the form ("Date de publication" and "Date d'expiration"). I currently have the following configuration in my ext_table.php
:
<?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');
?>
However, defining the columns as start and end access dates with
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['starttime'] = 'tx_myext_starttime';
$GLOBALS['TCA']['sys_file']['ctrl']['enablecolumns']['endtime'] = 'tx_myext_starttime';
as suggested in the answers makes the file list show an error instead of loading a list of files. Instead, I tried using the $TCA variable to define them. The error page shown by Typo3 is not shown anymore using this, but the editing page still can't be rendered successfully.
The $TCA configuration I added:
$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',
)
)
);
The following image shows what happens with this $TCA configuration added while trying to edit a file: https://i.sstatic.net/8VaCD.png
The TCEForm is simply not rendered and I don't know why. I'm not sure if my configuration in ext_tables.php
contains a bad configuration (especially in the $TCA config I added) or if the problem comes from another file in the extension.
What can be causing this error and how can I fix it?
Upvotes: 2
Views: 1158
Reputation: 1442
FAL (File Abstraction Layer) does not have a starttime
and endtime
field.
But since the sys_file
related tables (like sys_file_reference
) can be extended by your own extension and TCA offers you the starttime
/endtime
functionality by default my biggest guess will be that this can be accomplished with some modifications in the TCA.
Here a quick kickstart of how you can try to extend sys_file
with the starttime
and endtime
fields.
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);
I don't know if the FAL persistence layer and repositories does support (or better: eat) this configuration and I can't estimate in which kind of problems you're gonna run. But I guess it's a try worth.
Good luck!
Upvotes: 2