简体   繁体   中英

TYPO3 Custom Page Properties

I'm trying to make the Publish Date mandatory for my "Article" page type.

I added this code

$fields_article = array(
    'starttime' => [
        'label' => 'Publish Date',
        'config' => [
            'type' => 'input',
            'eval' => 'datetime,required'
        ],
    ]
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', $fields_article);
$showItem = "--div--;Page Settings";
$showItem .= ",--linebreak--,starttime";
$GLOBALS['TCA']['pages']['types'][$doktypeArticlePage] = array(
    'showitem' => $showItem
);

And this works, but it makes the Publish Date mandatory for all page types. Is it possible to only add the required tag to article page types?

There is no default way to set eval based on type, so I'm afraid there's no easy way to do this.

You could most likely do this with a custom eval. See the Vendor\\Extention\\* section in https://docs.typo3.org/typo3cms/TCAReference/latest/ColumnsConfig/Type/Input.html#eval for more information about that.

Alternatively you could create a new required field, which is only shown in your "Article" page type, and use one of the hook in TYPO3\\CMS\\Core\\DataHandling\\DataHandler to copy its value to the starttime field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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