Add TYPO3 palette to all elements? - php

I have made a custom palette in tt_content.php and want to add it to all content elements on the appearance tab like this:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tt_content',
'--palette--;My Palette;my_palette',
'',
'before:sectionIndex'
);
This works for everything except Grid Elements (gridelements_pi1). How do I make the new palette show up on Grid Elements as well?

The comment from #MathiasBrodala lead me to finding the answer is in the order of extensions.
In this case I needed to add gridelements under suggests in my ext_emconf.php which ensures it will be loaded before my site package.
$EM_CONF[$_EXTKEY] = [
'title' => 'My Package',
'description' => 'TYPO3 Sitepackage',
'category' => 'templates',
'version' => '1.0.0',
'state' => 'stable',
'constraints' => [
'depends' => [
'typo3' => '8.7.0-9.5.99',
'fluid_styled_content' => '8.7.0-9.5.99'
],
'suggests' => [
'gridelements' => '9.3.0-0.0.0',
],
'conflicts' => [
],
],
'uploadfolder' => 0,
'createDirs' => '',
'clearCacheOnLoad' => 1
];

Related

TYPO3 BE TCA type Preview Image

i search for a Solution:
How can i add a Preview Image for a TCA type?
Example: I have 3 different types and would like to display a preview image for them. The same as the t3 backend layouts.
Just like the Backend-Layout:
Maybe there is a solution to this?
The documentation is explaining it:
https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Columns/Examples.html#select-drop-down-for-records-represented-by-images
This is the example code:
[
'columns' => [
'select_single_12' => [
'label' => 'select_single_12 foreign_table selicon_field',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'tx_styleguide_elements_select_single_12_foreign',
'fieldWizard' => [
'selectIcons' => [
'disabled' => false,
],
],
],
],
],
]
And the code for the field of the connected table is this:
[
'ctrl' => [
'title' => 'Form engine elements - select foreign single_12',
'label' => 'fal_1',
'selicon_field' => 'fal_1',
// ...
],
'columns' => [
// ...
'fal_1' => [
'label' => 'fal_1 selicon_field',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'fal_1',
[
'maxitems' => 1,
],
$GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']
),
],
],
// ...
];
As you have a strange label inside your field it's not clear if you want to link to an image, to a text or even to a field that offers a combination like it's done with relations to the table sys_file by the intermediate table sys_file_ref.
So defining more precise what you need exactly might help to give you a more detailed answer. You can edit your answer to add this description.

TYPO3 - changing own Field on edit page by custom content element

I created a custom content element with TYPO3 ver. 10.4.21, but I have a problem.
Problem: showing up same Fields on every edit page of content elements.
I want to use own fields only on my custom content element (for my flipbox-content element). But if I select e.g. a regular text element, then I can see my own fields on the edit page by the text element too.
I wrote the codes in TCA/Overrides/tt_content.php:
###############################################
# Front side #
###############################################
// front side header
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
[
'tx_pagesaddfields_frontsideheader' => [
'exclude' => 0,
'label' => 'Front side header',
'config' => [
'type' => 'text',
'renderType' => 'input',
'items' => [
[
0 => '',
1 => ''
]
],
],
],
]
);
// front side bodytext
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
[
'tx_pagesaddfields_frontsidebodytext' => [
'label' => 'Front side bodytext',
'config' => [
'type' => 'text',
'cols' => 40,
'rows' => 15,
'enableRichtext' => true,
],
],
]
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
'tt_content',
'general',
'tx_pagesaddfields_frontsideheader, tx_pagesaddfields_frontsidebodytext',
'after:tx_container_parent'
);
###############################################
# Back side #
###############################################
// back side header
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
[
'tx_pagesaddfields_backsideheader' => [
'exclude' => 0,
'label' => 'Back side header',
'config' => [
'type' => 'text',
'renderType' => 'input',
'items' => [
[
0 => '',
1 => ''
]
],
],
],
]
);
// back side bodytext
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
[
'tx_pagesaddfields_backsidebodytext' => [
'label' => 'Back side bodytext',
'config' => [
'type' => 'text',
'cols' => 40,
'rows' => 15,
'enableRichtext' => true,
],
],
]
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
'tt_content',
'general',
'tx_pagesaddfields_backsideheader, tx_pagesaddfields_backsidebodytext',
'after:tx_pagesaddfields_frontsidebodytext'
);
I know because I wrote "addTCAcolumns('tt_content'). But I don't know how I can rewrite them to let show up my new fields only on my custom edit page.
Is it the right page to chage it?:
https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ExtensionArchitecture/ExtendingTca/Examples/Index.html
(by exanple1) and
https://docs.typo3.org/m/typo3/reference-tca/master/en-us/ColumnsConfig/Type/User/Index.html#columns-user?
I tried to do it, but it didn't work on my site. Unfortunately, I don't have enough experiences with PHP... If you know other website or if you can explain here, please write it down here.
I hope anyone can help me. Thank you.
It is best practice to add one file into TCA/Overrides/ per custom content element. The name is up to you, TYPO3 reads all .php files in this folder. content_element_<your_ctype>.php or tt_content_<your_ctype>.php are used as name quite often.
https://github.com/benjaminkott/bootstrap_package/blob/master/Configuration/TCA/Overrides/203_content_element_card_group.php
Here you can see how it is done in the bootstrap_package for the custom content element with the CType card_group
In line 42 $GLOBALS['TCA']['tt_content']['types']['card_group'] the configuration is limited to ['(C)type']['card_group'] and the 'showitem' => ' tells TYPO3 what and how to show fields for this content element.
From line 70 on you can see how to set a new field, in line 49 you can see how it was added.

TYPO3 8.7.24: graphical bug when using selectTree in tca

When I'm using rendermode selectTree for my kategorie selection, then I've got an graphical bug. The bug independent from browser (tested in chrome and firefox). I found out, that it looks like the svg icon I'm using for this type.
My tca config for the field "eltern":
'eltern' => [
'exclude' => true,
'label' => 'Eltern',
'config' => [
'type' => 'select',
'renderType' => 'selectTree',
'foreign_table' => 'tx_adressen_domain_model_adresskategorie',
'foreign_table_where' => 'ORDER BY tx_adressen_domain_model_adresskategorie.kategoriename',
'size' => 20,
'treeConfig' => [
'parentField' => 'eltern',
'appearance' => [
'expandAll' => true,
'showHeader' => true,
],
],
'maxitems' => 1,
'minitems' => 0,
],
],
Resolved the problem with using a 16x16 Pixel PNG icon instead of a svg icon
TCA:
return [
...
'iconfile' => 'EXT:adressen/Resources/Public/Icons/Adresskategorie.png',
...

TYPO3 How to add Create new button on TCA?

I would like to build a slider (Own Content Element). So on the backend i would like to have a section with multiple records. What do i mean? By clicking the "Create new" i would like to have an image selection and rich text selection.
Something like that.
How can i achieve this?
So far i have:
TCA/Overrides/tt_content.php
which gives me the rich editor and the image selection in backend, but not grouped.
$GLOBALS['TCA']['tt_content']['types']['my_slider'] = array( 'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.headers;headers,bodytext,assets;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
]
]
);
tt_content.typosript
tt_content {
my_slider < lib.contentElement
my_slider {
templateRootPaths.10 = {$Private}Templates/
templateName = Slider.html
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = assets
as = images
}
}
}
}
Slider.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<h1>{data.header}</h1>
<p>{data.bodytext}</p>
<f:for each="{images}" as="image">
<f:image image="{image}" alt="{file.properties.alt}" cropVariant="desktop"/>
{image.description}
</f:for>
<f:debug>{data}</f:debug>
</html>
Now with the current code i get the results in frontend. One Text and one Image. But how can i get it as group after configured it on the backend?
You need add new field to the sys_file_reference TCA:
Configuration/TCA/Overrides/sys_file_reference.php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'sys_file_reference',
[
'tx_myext_description' => [
'label' => 'My field description',
'config' => [
'type' => 'text',
'cols' => '80',
'rows' => '15',
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
],
]
);
ext_tables.sql
CREATE TABLE sys_file_reference (
tx_myext_description mediumtext,
);
Remember to add new field into database (using database compare tool in install tool).
Then use it in TCA of your new slider:
Configuration/TCA/Overrides/tt_content.php
$GLOBALS['TCA']['tt_content']['types']['my_slider'] = [
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.headers;headers,bodytext,assets;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
],
'assets' => [
'config' => [
'overrideChildTca' => [
'types' => [
0 => ['showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][0]['showitem'].',tx_myext_description'],
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION]['showitem'].',tx_myext_description'
],
],
],
],
],
],
];
And then your Fluid template may look like that:
Slider.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<h1>{data.header}</h1>
<p>{data.bodytext}</p>
<f:for each="{images}" as="image">
<f:image image="{image}" alt="{file.properties.alt}" cropVariant="desktop"/>
{image.properties.tx_myext_description -> f:format.html()}
</f:for>
</html>

TYPO3 how to add virtual column to the TCA?

how can I add an virtual column to the TCA (TYPO3 8)? I have in a 1:n table with data and I want to display the count of the data in the backend to current element.
I need something like this:
$fields = [
'counts7d' => [
'exclude' => false,
'label' => 'last 7 days',
'config' => [
'type' => 'none',
'procFunc' => '\Namespace\MyClass->MyMethod',
'readOnly' => true,
'params' => [
'period => '7d'
]
]
],
'counts30d' => [
'exclude' => false,
'label' => 'last 30 days',
'config' => [
'type' => 'none',
'procFunc' => '\Namespace\MyClass->MyMethod',
'readOnly' => true,
'params' => [
'period => '30d'
]
]
],
];
pseudo function:
public function myMethod($element, $params){
$sql = "SELECT count(*) FROM TABLE WHERE pid=$element[uid] and date > $params[period]";
return sql_count…
}
The field should only be informative for the backend users.
Does anyone have an idea?
Thanks
Oliver
The TCA field type user is exactly what you are looking for:
'counts7d' => [
'exclude' => false,
'label' => 'last 7 days',
'config' => [
'type' => 'user',
'userFunc' => \Namespace\MyClass::class . '->MyMethod',
'parameters' => [
'period => '7d',
],
],
],
The TCA field type none is exactly what you are looking for. Type none is the only type that does not necessarily need a database field. To manipulate it you can use userFunc which allow you to use custom php function.

Categories