The none field
There are three columns config types that do similar things but still have subtle differences between them. These are the none type, the passthrough type and the user type.
Characteristics of none:
- The DataHandler discards values send for type
noneand never persists or updates them in the database. - Type
noneis the only type that does not necessarily need a database field. - Type
nonefields does have a defaultrenderin FormEngine that displays the value as readonly if a database field exists and the value can be formatted.Type - If no database field exists for
nonefields, an empty readonly input field is rendered by default. - Type
nonefields are designed to be not rendered at other places in the backend, for instance they can not be selected to be displayed in the Content > Records module "single table view" if everything has been configured correctly.
The none field can be useful, if:
- A "virtual" field that has no database representation is needed. A simple example could be a rendered
map that receives values from
latitudeandlongitudefields but that needs to database representation itself. - A third party feeds the database field with a value and the value should be formatted and displayed
in FormEngine. However, a input type with
readis usually better suited to do that.Only=true
Since the formatting part of none fields can be done with input type as well, most useful usage
of type none fields is a "virtual" field that is combined with a custom
renderType by an extension.
The TYPO3 core makes little or no use of none fields itself.
Table of contents:
Example: Simple none field
A comment shows when it was written. The column crdate exists, as the
ctrl section of the comments names it, and TYPO3 sets its value. The
field of type none only displays it:
The time a comment was written
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
// Shows when a comment was written. TYPO3 sets the value, an editor
// cannot change it.
ExtensionManagementUtility::addTCAcolumns('tx_myextension_comment', [
'crdate' => [
'label' => 'my_extension.db:comment.crdate',
'config' => [
'type' => 'none',
'format' => 'datetime',
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_comment',
'crdate',
'',
'after:name',
);
Properties of the TCA column type none
| Name | Type | Scope |
|---|---|---|
| string (keyword) + array | Display | |
| integer | Display |
-
For details see fieldInformation.
-
- Type
- string (keyword) + array
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['format']
- Scope
- Display
The value of a none-type fields is normally displayed as is. It is however possible to format it using this property. The following keywords are available, some having sub-properties. Sub-properties are called with the
format.keyword (note the trailing dot), which in itself is an array.- date
-
Formats the value of the field as a date. The default formatting uses PHP's
datefunction and() d-as a format.m- Y Possible options are:
- strftime
- (boolean) If true,
strftimeis used instead() datefor formatting.() - option
- (string) Format string (i.e.
Y-orm- d %x, etc.). - appendAge
- (boolean) If true, the age of the value is appended is appended to the formatted output.
- datetime
- Formats the values using PHP's
datefunction and() H:as a format.i d- m- Y - time
- Formats the values using PHP's
datefunction and() H:as a format.i - timesec
- Formats the values using PHP's
datefunction and() H:as a format.i: s - year
- Formats the values using PHP's
datefunction and() Yas a format. - int
-
Formats the values as an integer using PHP's
sprintfin various bases. The default base is decimal (() dec). The base is defined as an option:- base
- (string) Defines the base of the value. Possible bases are "dec", "hex", "HEX", "oct" and "bin".
- float
-
Formats the values as an real number using PHP's
sprintfand the() %fmarker. The number of decimals is an option:- precision
- (integer) Defines the number of decimals to use (maximum is 10, default is 2).
- number
-
Formats the values as a number using PHP's
sprintf. The format to use is an option:() - option
- (string) A format definition according to PHP's
sprintffunction (see the reference).()
- md5
- Returns the md5 hash of the values.
- filesize
-
Formats the values as file size using
\TYPO3\. One option exists:CMS\ Core\ Utility\ General Utility:: format Size () - appendByteSize
- (boolean) If true, the original value is appended to the formatted string (between brackets).
- user
-
Calls a user-defined function to format the values. The only option is the reference to the function:
- userFunc
- (string) Reference to the user-defined function. The function receives the field configuration and the field's value as parameters.
The time a comment was written:
<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
// Shows when a comment was written. TYPO3 sets the value, an editor
// cannot change it.
ExtensionManagementUtility::addTCAcolumns('tx_myextension_comment', [
'crdate' => [
'label' => 'my_extension.db:comment.crdate',
'config' => [
'type' => 'none',
'format' => 'datetime',
],
],
]);
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_comment',
'crdate',
'',
'after:name',
);
The feedback form of the website stores when it opened for a talk, the average rating, and the number of feedback forms. The editors only read them:
<?php
use MyVendor\MyExtension\Backend\FeedbackCountFormatter;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
// The feedback form of the website stores these values, the editors only
// read them
ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
'feedback_opened' => [
'label' => 'my_extension.db:talk.feedback_opened',
'config' => [
'type' => 'none',
// For example "05/12/2027 (5 days)"
'format' => 'date',
'format.' => [
'strftime' => true,
'option' => '%x',
'appendAge' => true,
],
],
],
'rating' => [
'label' => 'my_extension.db:talk.rating',
'config' => [
'type' => 'none',
// The average of all ratings, for example "4.3"
'format' => 'float',
'format.' => [
'precision' => 1,
],
],
],
'feedback_count' => [
'label' => 'my_extension.db:talk.feedback_count',
'config' => [
'type' => 'none',
// For example "12 attendees"
'format' => 'user',
'format.' => [
'userFunc' => FeedbackCountFormatter::class . '->format',
],
],
],
]);
$GLOBALS['TCA']['tx_myextension_talk']['palettes']['feedback'] = [
'label' => 'my_extension.db:talk.feedback',
'showitem' => 'feedback_opened, rating, feedback_count',
];
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'--palette--;;feedback',
'talk,keynote',
'after:comments_closed',
);
// In a workshop, the participants give the feedback
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'--palette--;my_extension.db:talk.feedback.workshop;feedback',
'workshop',
'after:comments_closed',
);
<?php
use MyVendor\MyExtension\Backend\FeedbackCountFormatter;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
// The feedback form of the website stores these values, the editors only
// read them
ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
'feedback_opened' => [
'label' => 'my_extension.db:talk.feedback_opened',
'config' => [
'type' => 'none',
// For example "05/12/2027 (5 days)"
'format' => 'date',
'format.' => [
'strftime' => true,
'option' => '%x',
'appendAge' => true,
],
],
],
'rating' => [
'label' => 'my_extension.db:talk.rating',
'config' => [
'type' => 'none',
// The average of all ratings, for example "4.3"
'format' => 'float',
'format.' => [
'precision' => 1,
],
],
],
'feedback_count' => [
'label' => 'my_extension.db:talk.feedback_count',
'config' => [
'type' => 'none',
// For example "12 attendees"
'format' => 'user',
'format.' => [
'userFunc' => FeedbackCountFormatter::class . '->format',
],
],
],
]);
$GLOBALS['TCA']['tx_myextension_talk']['palettes']['feedback'] = [
'label' => 'my_extension.db:talk.feedback',
'showitem' => 'feedback_opened, rating, feedback_count',
];
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'--palette--;;feedback',
'talk,keynote',
'after:comments_closed',
);
// In a workshop, the participants give the feedback
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'--palette--;my_extension.db:talk.feedback.workshop;feedback',
'workshop',
'after:comments_closed',
);
<?php
use MyVendor\MyExtension\Backend\FeedbackCountFormatter;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
defined('TYPO3') or die();
// The feedback form of the website stores these values, the editors only
// read them
ExtensionManagementUtility::addTCAcolumns('tx_myextension_talk', [
'feedback_opened' => [
'label' => 'my_extension.db:talk.feedback_opened',
'config' => [
'type' => 'none',
// For example "05/12/2027 (5 days)"
'format' => 'date',
'format.' => [
'strftime' => true,
'option' => '%x',
'appendAge' => true,
],
],
],
'rating' => [
'label' => 'my_extension.db:talk.rating',
'config' => [
'type' => 'none',
// The average of all ratings, for example "4.3"
'format' => 'float',
'format.' => [
'precision' => 1,
],
],
],
'feedback_count' => [
'label' => 'my_extension.db:talk.feedback_count',
'config' => [
'type' => 'none',
// For example "12 attendees"
'format' => 'user',
'format.' => [
'userFunc' => FeedbackCountFormatter::class . '->format',
],
],
],
]);
$GLOBALS['TCA']['tx_myextension_talk']['palettes']['feedback'] = [
'label' => 'my_extension.db:talk.feedback',
'showitem' => 'feedback_opened, rating, feedback_count',
];
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'--palette--;;feedback',
'talk,keynote',
'after:comments_closed',
);
// In a workshop, the participants give the feedback
ExtensionManagementUtility::addToAllTCAtypes(
'tx_myextension_talk',
'--palette--;my_extension.db:talk.feedback.workshop;feedback',
'workshop',
'after:comments_closed',
);
The user function receives the value of the field:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Backend;
use TYPO3\CMS\Core\Localization\LanguageService;
final class FeedbackCountFormatter
{
/**
* Shows the number of feedback forms as text, for example "12 attendees"
*/
public function format(array $parameters): string
{
$count = (int)($parameters['value'] ?? 0);
$label = $count === 1 ? 'talk.feedback_count.one' : 'talk.feedback_count.other';
return sprintf($this->getLanguageService()->sL('my_extension.db:' . $label), $count);
}
private function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}
}
-
- Type
- integer
- TCA path
- $GLOBALS['TCA'][$table]['columns'][$field]['config']['size']
- Scope
- Display
Value for the width of the
<input>field. To set the input field to the full width of the form area, use the value 50. Default is 30.