TYPO3 TCA label with UserFunc - how to get HTML formatted label? - typo3

I want to format the title showing in a list of TCA items which can contain italic text. But whatever I try, I get only unformatted text - even from RTE text fields.
My base information is "partA", "partB", "partC" and I need a title like "partA : partC - part B"
My Code so far:
<?php
return [
'ctrl' => [
'title' => 'LLL:EXT:myext/Resources/Private/Language/myext.xlf:tx_myext_domain_model_myitem',
'label' => 'partC',
'label_alt' => 'partA',
'formattedLabel_userFunc' => T395\myExt\Classes\UserFuncs\MyBEUserFuncs::class.'->getFullMyitemTitle',
'formattedLabel_userFunc_options' => [
'sys_file' => [
'partC','partA','partB'
]
],
'iconfile' => 'fileadmin/Resource/icons/svgs/myext.svg',
],
'columns' => [
'partC' => [
'label' => 'LLL:EXT:myext/Resources/Private/Language/myext.xlf:tx_myext_domain_model_myitem.partC',
'config' => [
'type' => 'text',
'enableRichtext' => true,
],
],
'partA' => [
'label' => 'LLL:EXT:myext/Resources/Private/Language/myext.xlf:tx_myext_domain_model_myitem.partA',
'config' => [
'type' => 'input',
'size' => '5',
'eval' => 'trim',
],
],
'partB' => [
'label' => 'LLL:EXT:myext/Resources/Private/Language/myext.xlf:tx_myext_domain_model_myitem.partC',
'config' => [
'type' => 'input',
'size' => '5',
'eval' => 'trim',
],
],
],
'types' => [
'0' => ['showitem' => 'partA,partB,partC'],
],
];
And the UF:
<?php
T395\myExt\Classes\UserFuncs;
class MyBEUserFuncs
{
public function getFullMyitemTitle(&$params, &$pObj)
{
echo "Hello World!";
$params['title'] = $params['row']['partA'].' : '.$params['row']['partC'].' - '.$params['row']['partB'];
}
}
Even the echo is not showing. Changing the formattedLabel_userFunc to label_userFunc results in getting a string in right order - but right without any text formats like <i> etc but showing them as text. I'm sure, I'm missing something, but I can't figure out what it is - I was also unable to find any code snippets or examples showing the right way - and the docs from TYPO3 saying only that exists formattedLabel_userFunc and it has options - but no proper example there. Hope you can help me. Thank you!

in the documentation for formattedlabel_userfunc you can find:
[...] return formatted HTML for the label and used only for the labels of inline (IRRE) records.
and for label_userfunc there is the warning:
The title is passed later on through htmlspecialchars() so it may not include any HTML formatting.

Related

TYPO3 Prefill text field in my own extension

I need to save the IP address of a user who fills out my form.
I have tried to do it like this:
'userip' => [
'exclude' => true,
'label' => 'LLL:EXT:myExtension/Resources/Private/Language/locallang_db.xlf:tx_myextension_domain_model_myextension.userip',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'trim',
'default' => '12345'.$_SERVER["REMOTE_ADDR"]
]
],
But that doesn't work. What would be the right way?
$_SERVER["REMOTE_ADDR"] is not available in TCA cause this is BE related stuff.
Use the setter from the model, setUserip($_SERVER["REMOTE_ADDR"]), in your createAction() or initializeCreateAction() to save the value in DB.

TYPO3 TCA: Add CSS class selection to inputLink

I'm trying to add a CSS class selection in a TCA inputLink Field. I was able to create the selection in the RTE Editor and now I want to be able to select the same CSS classes in TCA link input fields.
Here is my current code:
'link' => [
'exclude' => 1,
'label' => 'foo label',
'config' => [
'type' => 'input',
'renderType' => 'inputLink',
'size' => 50,
'max' => 1024,
'eval' => 'trim',
'fieldControl' => [
'linkPopup' => [
'options' => [
'title' => 'foo title',
'class' => [
'valuePicker' => [
'mode' => 'blank',
'items' => [
['button', 'Button Style'],
],
],
],
],
],
],
'softref' => 'typolink',
],
],
I couldn't find anything in the TCA Docs. I thought I would give it a try with the LinkPopup --> options --> class. But (as expected) nothing happens.
How am I able to define such a selection dropdown in the link input field?
I'm using TYPO3 LTS 11.
Not sure if you have configured, what you are describing...
A valuePicker can be placed next to an input field of RenderTypes default, colorpicker, inputLink (-> TCAref). The class field in the linkPopup is a simple (hardcoded) form field without a defined renderType or other TCA configuration (Code insight).
There are only a few options for configuring a linkpopup (-> TCAref):
pid
allowedExtensions
blindLinkFields
blindLinkOptions
Setting a prefilled (not selectable) class seems to be possible via TCAMAIN.linkHandler-options (-> LinkBrowser-API). I found an example in an issue of EXT:bootstrap_package.

Missing TCA labels in inline tt_content relation

We are using the Mask extension for some of our content Elements. (It basically adds dynamic CTypes and additional columns in the tt_content).
Next we have our custom extension whose entities should have a relation to an instance of a Mask module. Which works. The only problem is, that the labels of the inline element aren't showing up.
If we add the same Mask module as normal page content, the labels are showing up just fine.
Domain Model of our ext:
/**
* Returns the intro
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\MASK\Mask\Domain\Model\Content> $intro
*/
public function getIntro()
{
return $this->intro;
}
TCA
'intro' => [
'exclude' => 0,
'label' => 'Intro zentriert',
'config' => [
'type' => 'inline',
'foreign_table' => 'tt_content',
'foreign_field' => 'tx_zeppelinregions_content_elements',
'foreign_label' => 'tx_mask_teasergalleryheadline',
'foreign_table_field' => 'tx_zeppelinregions_content_elements_type',
'maxitems' => 1,
'foreign_match_fields' => [
'ctype' => 'mask_introzentriert',
],
'overrideChildTca' => [
'columns' => [
'CType' => [
'config' => [
'default' => 'mask_introzentriert',
'readOnly' => 1,
],
],
],
],
]
],
Missing labels in inline element:
(Note: the default tt_content field labels are showing)
Labels showing when adding an element of the same type as normal page content:

TCA file, checkbox default checked

I would like to set a checkbox in the backend to default checked.
In my case it is the field showinpreview in the file /typo3conf/ext/news/Configuration/TCA/tx_news_domain_model_media.php.
I changed the value default to 1, but it has no effect:
'showinpreview' => [
'exclude' => 1,
'label' => $ll . 'tx_news_domain_model_media.showinpreview',
'config' => [
'type' => 'check',
'default' => 1
]
],
When I check the TCA File of tt_content for a checked checkbox it looks like this:
'sectionIndex' => [
'exclude' => 1,
'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:sectionIndex',
'config' => [
'type' => 'check',
'default' => 1,
'items' => [
'1' => [
'0' => 'LLL:EXT:lang/locallang_core.xlf:labels.enabled'
]
]
]
],
The only difference I see is the items. But I do not really understand what this item-value does.
The easiest way to change this value is by overriding TCA with some pageTS. Add following to the pagets of the folder that holds the news records.
TCAdefaults.sys_file_reference.showinpreview = 1
See https://docs.typo3.org/typo3cms/TSconfigReference/PageTsconfig/TCEform/Index.html
For the older EXT:news versions use: TCAdefaults.tx_news_domain_model_media.showinpreview = 1
The value of the field showinpreview is set in news/Configuration/TCA/Overrides/sys_file_reference.php. Apply your change there, and you will be happy.
But be aware: after updating of the news extension your change will be lost.
Just checked - this works for me
'checkbox' => array(
'exclude' => 0,
'label' => 'My Label',
'config' => array(
'type' => 'check',
'default' => '1'
)
),

Populating $form_input with 'select' element options?

I'm trying to understand the data-structure required to populate a
form with 'select' element values (options).
When I dump (Data::Dumper) the FormFu object, I see that the object structure
looks similar to the following:
'name' => 'EmailDL',
'_options' => [
{
'label_attributes' => {},
'value' => 'm',
'container_attributes' => {},
'label' => 'Male',
'attributes' => {}
},
{
'label_attributes' => {},
'value' => 'f',
'container_attributes' => {},
'label' => 'Female',
'attributes' => {}
}
],
Seeing this, I figured that the way to structure $form_input (being that $form_input = \%cgivars) would be something like the following:
'Firstname' => 'Faisal',
'EmailDL' => [
{
'value' => 'myvalue',
'label' => 'mylabel'
}
],
However this doesn't seem to work. I've found that structuring $form_input correctly, and then issuing a $fu->default_values($form_input) to be simple and effective, except in this instance when I'm trying to include the select/options sub-structure.
So the question is: How should I structure 'EmailDL' above to correctly populate 'select' options when doing $fu->default_values($form_input) or $fu->process($form_input)?
To set the options you use the options call,
$fu->get_all_element('EmailDL')->options([ [ 'myvalue', 'mylabel' ],
[ 'val2', 'label2' ] ]);
If you then want to set one of those values you can use the default_values.
$fu->default_values({ EmailDL => 'val2' });
Further help is available here in the Element::Group documentation. Note the code examples are in the text of the help.