TYPO3 new tab to custom extension - typo3

I write my own extension. I have the file tx_xyz_domain_model_abc.php
with following code:
'types' => [
'1' => [
'showitem' => '
--div--;Article, title,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language, sys_language_uid, l10n_parent, l10n_diffsource,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, hidden, starttime, endtime,
'],
],
so the first line is my new field. The other lines are TYPO3 defaults. A --div-- is a new tab. How can i add the media or general tab to my extension?
I've tried to add
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
But there is no new tab. How can i do this?

--palette--; will insert a new palette (=grouped fields) to the current tab (-> TCA ref).
Without defining a tab, the fields are automatically put in a "General"-Tab at first position.
'types' => [
'0' => [
'showitem' => '
hidden, title,
--div--;LLL:EXT:examples/locallang_db.xml:tx_examples_product.images, image1, image2,
'
],
],
For further tabs, you need to insert a "--div--;label"-value in the field list (-> TCA ref):
'types' => [
'0' => [
'showitem' => '
hidden, title,
--div--;LLL:EXT:examples/locallang_db.xml:tx_examples_product.text, description, teaser,
--div--;LLL:EXT:examples/locallang_db.xml:tx_examples_product.images, image1, image2,
'
],
],

To show the core general tab in your extension is not possible. You wrote your own extension with your own data model. This is saved in db table tx_xyz_domain_model_abc. But data in core are from table tt_content which has a separate TCA.
You can
Extend table tt_content with your extension. Then you can use fields from tt_content
Add fields like header in your extension and table

Related

get mergedProperties of sys_file_reference in tx_news

I am using TYPO3 9.5.26 with tx_news 8.5.2. I have extended sys_file_reference with my own field. I can access this fields value in my fluid templates like so:
{file.properties.tx_myext_frame}
This is tested and works fine. However in the news module this stays empty
{mediaElement.properties.tx_myext_frame}
How can I use the orginalFile properties in tx_news?
Thanks
Code I use to add the field:
typo3conf\ext\myext\ext_tables.sql
CREATE TABLE sys_file_reference (
tx_myext_frame tinyint(4) DEFAULT '0' NOT NULL,
);
typo3conf\ext\myext\Configuration\TCA\Overrides\sys_file_reference.php
// Add some fields to sys_file_reference table
$temporaryColumns = [
'tx_myext_frame' => [
'exclude' => 0,
'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:tx_myext_frame',
'config' => [
'type' => 'check',
'default' => '0',
]
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
'sys_file_reference',
'imageoverlayPalette',
'--linebreak--,tx_myext_invert,tx_myext_frame',
'after:description'
);
found the answer myself just now - so for anyone trying this use
{mediaElement.originalResource.properties.tx_myext_frame}

Add another picture to content element in typo3

I'm creating my own content element to display some text, some image and another image. This is my tt_content.php file.
'logo' => [
'label' => 'dfasad',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'logo',
[
'overrideChildTca' => [
'types' => [
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
'showitem' => '
--palette--;LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
--palette--;;filePalette'
],
],
],
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
This gives me an input field on the backend but it does not get saved on the db.
Probably I need to set that too, right?
I've seen the documentation but is not clear for, I can copy and paste the code and even if would work I would never know why.
You need to define a database field in the ext_tables.sql file of your extension.
CREATE TABLE mytablename (
logo int(11) DEFAULT '0' NOT NULL,
);
You need to set mytablename to the name of the table you're extending or your own table name.
See the documentation for details.

TYPO3: How to configure $GLOBALS['TCA']['tt_content']['types']

I have an extension with a content element. I want to display it in the content element wizard. For this, I created tt_content.php. The code in it looks like this:
$GLOBALS['TCA']['tt_content']['types']['extensionkey_contentelementname'] = array(
'types' => [
'0' => [
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, category, subject, message,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, personal
',
],
]
);
(I obviously replaced extensionkey_contentelementname with the real name)
This throws me an error when trying to create the content element:
No or invalid showitem definition in TCA table tt_content for type extensionkey_contentelementname
What did I do wrong?
You are adding two array levels too much. You are already in $GLOBALS['TCA']['tt_content']['types'], so the typesand 0 is not needed anymore.
https://docs.typo3.org/typo3cms/extensions/fluid_styled_content/7.6/AddingYourOwnContentElements/Index.html#configuration-tca-overrides-tt-content-php
In Configuration/TCA/Overrides/tt_content.php:
$GLOBALS['TCA']['tt_content']['types']['extensionkey_contentelementname'] = [
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, category, subject, message,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, personal
',
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'My content element',
'extensionkey_contentelementname',
'content-image',
],
'textmedia',
'after'
);
You got a duplicate 'types' there.
Use this in page TS config to have it in the content element wizard.
$GLOBALS['TCA']['tt_content']['types']['extensionkey_contentelementname'] = [
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, category, subject, message,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access, personal
',
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'My content element',
'extensionkey_contentelementname',
'content-image',
],
'textmedia',
'after'
);

TYPO3 - Extension TCA - Show backend fields

I'm deveopping my own Typo3 extension and it's not as easy as expected :)
When i create an object in the backend it's working :
But I can't find a way to display the following commands :
move up
move down
enable/disabled
Here is what I tried to show the "enable/disable" icon :
$TCA['tx_productsfaq_domain_model_scenario'] = array (
'ctrl' => array (
'enablecolumns' => [
'disabled' => 'hidden'
]
)
);
.. with no success. In my database the model has a "hidden" column (tinyint). Maybe I forgot something ? All other properties in my TCA work fine.
You need a sorting field in your Database
CREATE table tx_productsfaq_domain_model_scenario (
...
sorting int(11) DEFAULT '0' NOT NULL,
deleted tinyint(4) DEFAULT '0' NOT NULL,
hidden tinyint(4) DEFAULT '0' NOT NULL,
...
);
and TCA configuration like
$TCA['tx_productsfaq_domain_model_scenario'] = array (
'ctrl' => [
...
'sortby' => 'sorting',
'enablecolumns' => [
'disabled' => 'hidden'
],
...
]
);
It seems you are using the old way to configure your TCA. Please see https://docs.typo3.org/typo3cms/TCAReference/Introduction/Index.html
Use EXT:productsfaq/Configuration/TCA/tx_productsfaq_domain_model_scenario.php
return [
'ctrl' => [
...
'sortby' => 'sorting',
'delete' => 'deleted',
'enablecolumns' => [
'disabled' => 'hidden',
],
...
],
'interface' => [
'showRecordFieldList' => 'hidden, ...'
],
'types' => [
'0' => ['showitem' => 'hidden, ...']
],
'columns' => [
...
]
];
Depending on your TYPO3 version move up, move down will be visible if you switch on extended view and have defined a sorting field (by default it is called sorting with type int).
To have the correct fields and options for sorting and hiding you may use the EXT:extension_builder and generate a dummy extension to identify these fields.
Compare your definition and declaration of the fields ('sorting', 'hidden') in TCA and SQL(!) to a build in table like tt_content.

Adding new checkbox field to tx_news_domain_model_media

I am trying to add a new checkbox field 'showinhome' to the table 'tx_news_domain_model_media' same to the field 'showinpreview' here is my TCA Configuration in Configuration/TCA/Overrides/tx_news_domain_model_media.php
$temporaryColumns = [
'showinhome' => [
'exclude' => 1,
'label' => 'Show in Home',
'config' => [
'type' => 'check',
'default' => 0,
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tx_news_domain_model_media',
$temporaryColumns
);
$GLOBALS['TCA']['tx_news_domain_model_media']['ctrl']['label_alt'] .= ', showinhome';
$GLOBALS['TCA']['tx_news_domain_model_media']['interface']['showRecordFieldList'] .= ', showinhome';
$GLOBALS['TCA']['tx_news_domain_model_media']['palettes']['newsPalette']['showitem'] .= 'showinhome,';
The field is not displayed, can someone help me please?
You have mixed up some stuff here.
First: tx_news can use either the own media model or the native FAL relations. I personally always use the native FAL relation.
If you want to add this field to the media table, then there is no newsPalette there. You can use the below code to add the new field:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tx_news_domain_model_media', $temporaryColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tx_news_domain_model_media', implode(',', array_keys($temporaryColumns)));
If you using the normal FAL relation then the showinpreview field is added to the sys_file_reference table's TCA configuration and not to the tx_news_domain_model_media table.
If you want to add this field to the file, then you need to add it to the sys_file_reference field the same way tx_news does it (I guess that you already copied the code from it's override file)
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file_reference', $temporaryColumns);
// add special news palette
$GLOBALS['TCA']['sys_file_reference']['palettes']['newsPalette']['showitem'] .= ', showinhome';
Last but not least: you have to specify tx_news as a dependency in your extension, otherwise TYPO3 does not know that your extension has to be loaded after tx_news. If you change the dependency after you installed your extension you probably need to uninstall and install it again in the extension manager.