TYPO3 selectMultipleSideBySide translate "Available Items" per record type - typo3

I want to override the label strings "Available Items" and "Selected Items" in a selectMultipleSideBySide form because it is too generic. I have multiple record types using this form template so I cannot change the strings globally.
I tried to change it in the TCA of my custom record type without success. I only see the label for the entire relation.
I am using TYPO3 8.7
Does anyone know an extension which accomplished this or does anyone know the config path to there?
Thanks!
Edit:
In the class typo3/sysext/backend/Classes/Form/Element/SelectMultipleSideBySideElement.php at line 393 I found the translation path hard-coded. So I need to inherit from this class and register it as my new selectMultipleSideBySide in the TCA.

I copied the class TYPO3.CMS/typo3/sysext/backend/Classes/Form/Element/SelectMultipleSideBySideElement.php to my extension in Classes/From/Element/SelectTagCloudElement.php
I adapted namespace to my extensions.
I add a use-directive of use TYPO3\CMS\Backend\Form\Element\SelectMultipleSideBySideElement;.
I adapt the translation string like in line 221 to my custom records translation xml file.
I found on https://docs.typo3.org/m/typo3/reference-coreapi/8.7/en-us/ApiOverview/FormEngine/Rendering/Index.html a snippet to register an new NodeType (the class I extended previously) using:
// Add new field type to NodeFactory
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1487112284] = [
'nodeName' => 'selectTagCloud',
'priority' => '70',
'class' => \MyVendor\CoolTagCloud\Form\Element\SelectTagCloudElement::class,
];
in ext_localconf.php
Now I can use selectTagCloud instead of selectMultipleSideBySide in the TCA.
"Dump Autoload Information" in the Install Tool
Done

Related

TYPO3 FAL : add and read a custom field in a fluid template

In my custom extension I introduced a binary variable to the image metadata that needs to be read, similar to the "Show in list view" of tx_news.
With tx_news as example I was able to add the variable, the new palette shows the checkbox in the backend and the selection is registered in a new database field in the sys_file_reference table ...
I first tried to declare it in the domain which did work but I could not use the variable since it was an array of the same files in which I tried to use it, calling it within a loop broke the loop ... (this was my question)
now I need to use this new variable in my fluid template, if I loop trough the items the new variable named opentab is visible if I debug like this:
<f:for each="{object.items}" as="item" iteration="iteration">
<f:debug>{item.originalResource}</f:debug>
# debug result
TYPO3\CMS\Core\Resource\FileReferenceprototypeobject
propertiesOfFileReference => array(36 items)
uidOfFileReference => NULL
name => NULL
originalFile => TYPO3\CMS\Core\Resource\Fileprototypeobject
mergedProperties => array(empty)
propertiesOfFileReference has "title" which I can use like this {item.originalResource.title}
in propertiesOfFileReference I see "opentab" with its correct value but I found no way to use it !!!
Use {item.originalResource.properties.opentab}

How to enable header_position in TYPO3 7.6

In versions prior to TYPO3 7.6 you could select a position for your header within your content element (left, middle, right as far as I remember).
The field which has been used for storing that information in tt_content header_position is still available.
However, it will not appear in the backend.
I'm also using fluid_styled_content for rendering my content, and the Header partial doesn't contain any reference to the position, but only to the layout field.
My question is: How can I reenable that field and use it to position my headers?
You have to build a quick extension of yours which can reenable the field. You need to create folders and a file like following:
your_ext/Configuration/TCA/Overrides/tt_content.php
the contents of that file are:
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addTCAcolumns('tt_content',[
'header_position' => [
'exclude' => 1,
'label' => 'LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tt_content.header_position',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tt_content.header_position.left', 'left'],
['LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tt_content.header_position.right', 'right'],
['LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:tt_content.header_position.center', 'center']
]
]
]
]);
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'header', '--linebreak--,header_position', 'after:header_layout');
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'headers', '--linebreak--,header_position', 'after:header_layout');
Now the field should be back in the backend, because you've added it to the TCA via addTCAColumns to the tt_content configuration and added it via addFieldsToPalette to the header and headers palettes of tt_content, which are used by the types textmedia and header.
You can find out more about this by using the Configuration module in the TYPO3 backend. You can see it, when you are logged in as admin. Also a good place to look and learn about the TCA is the TCA reference: https://docs.typo3.org/typo3cms/TCAReference/
Now you need to alter the fluid_styled_content templates. You need to create template overrides for the header partial of fluid_styled_content.
First create a folder: your_ext/Configuration/TypoScript and add a setup.txt and a constants.txt file.
In setup.txt add the following lines:
lib.fluidContent{
templateRootPaths{
10 = {$plugin.your_ext.view.fluid_styled_content.templateRootPath}
}
partialRootPaths{
10 = {$plugin.your_ext.view.fluid_styled_content.partialRootPath}
}
layoutRootPaths{
10 = {$plugin.your_ext.view.fluid_styled_content.layoutRootPath}
}
}
In constants.txt do:
plugin.your_ext{
view{
fluid_styled_content{
templateRootPath = EXT:your_ext/Resources/Private/FluidStyledContent/Templates/
partialRootPath = EXT:your_ext/Resources/Private/FluidStyledContent/Partials/
layoutRootPath = EXT:your_ext/Resources/Private/FluidStyledContent/Layouts/
}
}
}
To enable your TypoScript, you need to add a ext_tables.php in your your_ext folder and give it the following one-liner:
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY,'Configuration/TypoScript', 'Your Ext Template');
You need to include your static TypoScript to your page via the Template module to enable the change to fluid_styled_content
Now you can copy the templates you need from
typo3/sysext/fluid_styled_content/Resources/Private/Templates
typo3/sysext/fluid_styled_content/Resources/Private/Partials
typo3/sysext/fluid_styled_content/Resources/Private/Layouts
into your extensions folders you need to create:
your_ext/Resources/Private/FluidStyledContent/Templates
your_ext/Resources/Private/FluidStyledContent/Partials
your_ext/Resources/Private/FluidStyledContent/Layouts
Now you can alter the templates. For your header_position field, you probably just need to copy
typo3/sysext/fluid_styled_content/Resources/Private/Partials/Heaeder.html
to
your_ext/Resources/Private/FluidStyledContent/Partials/Header.html
and add your selected value as {data.header_position} to a div class and style that.
Keep in mind you do not need to copy all of the templates, because with the TypoScript you just defined another location for fluid to search for templates and take them, if they are available. If not, fluid will walk back the chain and take the templates that are defined at position 9 and lower. You can look into the TypoScript Object Browser by the Template module and look into the TypoScript variable lib.FluidContent to see, if your TypoScript include has worked.
Hope this helped a bit ;)
The database field header_position is only included in the TYPO3 core extension css_styled_content. If you don't have that extension installed the field in the database is probably there because it was installed sometime before.
It is not advised to install css_styled_content and fluid_styled_content installed in parallel as some options can conflict.
If you want to use fluid_styled_content and have the header_position field available the best way to go would be to create a very small TYPO3 extension yourself that includes the necessary SQL definition for the column header_position, the appropriate TCA configuration for that column and a few bits of TypoScript to extend/override the „Partial” paths of fluid_styled_content.

How does my extension read bodytext fields from tt_content in TYPO3 CMS 7.6?

I'm writing a TYPO3 extension using TYPO3 CMS 7.6.x LTS and Extension Builder. One of my extension's tasks is to scan through the "header" and "bodytext" fields of TYPO3's tt_content table; match specific text patterns in "bodytext"; parse the found text; and put the resulting data into my extension's log table along with a label from the tt_content "header" field.
"Using Foreign Data Sources" in "Developing TYPO3 Extensions with Extbase and Fluid" at [ https://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/4-use-foreign-data-sources.html ] talks about putting data INTO tt_address using a TypoScript mapping. Instead, I'm reading data FROM tt_content, and would rather stay within PHP in the extension.
Using the graph in Foreign Key to TYPO3 Frontend User as an example, I added a second model to my extension's domain model in Extension Builder. I made a "TtContent" model, and used its "Domain object settings" to "map to existing table", its entry being "tt_content". I did NOT enter a value into the "extend using model class" field. I made a "relation" field in my Log model, and ran a wire connected from my Log:ttContent relation field to the title bar of my TtContent model. When I then clicked "Save", Extension Builder replied: "The configuration for table "tt_content" is not compatible with extbase. You have to configure it yourself if you want to map to this table (Error 606)". I don't understand this error message.
In Extension Builder, do I make a relation in my Log model to an existing external class? If so, which external class do I use? Or, do I make a model of tt_content in Extension Builder, and somehow get through that error 606? It shouldn't seem hard to do, because I want to read from an existing table already in TYPO3.
Solution: Create an Extbase model and a repository representing the existing tt_content table, then write a TypoScript property mapping.
In TYPO3 Extension Builder's domain modeller, add a model called "Content" or some name that reminds you of the tt_content table. In the "domain object settings" part of your Content model, put "tt_content" in the "map to existing table" box. Nevermind the "extend existing model class" box, because Extbase doesn't have such a class for tt_content.
Also in the domain object settings, set object type to "Entity", check the "is aggregate root" box, and uncheck the "add deleted field", "add hidden field", "add starttime/endtime fields", and "enable categorization" boxes. Setting the object type to "entity" and checking the "is aggregate root?" box causes Extension Builder to create a repository for your Content model.
Add properties to your Content model that represent the columns you want to access in the tt_content database table. In my Content model, I added only "header" and "bodytext" properties.
Note: You need not add TYPO3's uid or pid properties to the Content model. These properties have been extended from the parent \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject class.
Click "Save" in Extension Builder to save your new domain model. You will receive a message: "Warning! The configuration for table "tt_content" is not compatible with extbase. You have to configure it yourself if you want to map to this table (Error 606). Do you want to save anyway?" Yes, save anyway. Extension Builder will respond, "Success. The Extension was saved. Your Extension is not installed yet." Exit Extension Builder.
Note: If you go through several modelling iterations in Extension Builder, you may find artifacts in the extension's final code, left over from your earlier iterations. Extension Builder overwrites some of your extension areas, but leaves other areas alone. See the Extension Builder configuration reference at [ https://docs.typo3.org/typo3cms/extensions/extension_builder/Configuration/Index.html ].
Use Extbase table mapping to configure and thereby access content from the TYPO3 tt_content table. Do this configuration with TypoScript "config.tx_extbase.persistence.classes" mapping parameters in the "typo3conf/ext/yourextensionkey/ext_typoscript_setup.txt" file. Extension Builder created this file when you saved your domain model. This is the configuring mentioned in Error 606.
See the code example in "Using Foreign Data Sources" at [ https://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/4-use-foreign-data-sources.html ]. This TypoScript code example defines the mapping lines themselves. You may wish to use "config.tx_extbase" instead of "plugin.tx_myextension". The next page, "Modeling the Class Hierarchy" at [ https://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/5-modeling-the-class-hierarchy.html ], has a code example for "config.tx_extbase"; but it doesn't show the mapping lines themselves.
In my situation, I added TypoScript instructions in ext_typoscript_setup.txt to map the "header" and "bodytext" columns. I also deleted the recordType = Tx_Myextensionkey_Content line that Extension Builder wrote, because I want to read tt_content records that already exist, not records made by my extension.
config.tx_extbase{
persistence{
classes{
Mynamespace\Myextensionkey\Domain\Model\Content {
mapping {
tableName = tt_content
columns {
header.mapOnProperty = header
bodytext.mapOnProperty = bodytext
}
}
}
}
}
}
My TYPO3 extension can now read from tt_content.
Note: Giving a value to recordType in ext_typoscript_setup.txt causes the Extbase persistence layer to search for that one value in the underlying tt_content.CType column. Extbase does this through its \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager getConfiguration() $frameworkConfiguration array, and its \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory buildDataMapInternal() function. As of this writing, you cannot use a wildcard character such as * or % in your recordType value; and you cannot give a value list such as text, textmedia.

Extend/Change extensions in TYPO3

I wanted to ask, how to change files in a TYPO3-Extension, that they wont be overwritten after an update of the specific extensions.
I know that there are 'hooks', but they only give me some functions, not the hole controller file of an action.
Are there some best practices or do I only have the option to never update that extension?
Greets
Agash Thamo.
This depends on various factors.
Extbase Extensions
If the Extension is based on Extbase, you could write your own Extension with your custom Controller and use the domain model of the original extension. Since you didn't really specify which extension you want to modify, this is only a general approach.
Hooks
Are not necessarily provided by extensions. You can always ask the extension author to provide a new hook.
XCLASS
With XCLASS, you can overwrite a class from your own extension. You can find more information about this here. If you update the original extension, you probably need to adjust your XCLASS code.
Directly modify an existing Extension
You should avoid doing this. But if it is your only option, you can modify the file "ext_emconf.php" of the extension and set "state" to "excludeFromUpdates":
$EM_CONF[$_EXTKEY] = array(
'title' => 'Extension Title',
'description' => '',
'category' => 'plugin',
'state' => 'excludeFromUpdates',
...
);
This excludes an extension from updates.

Silverstripe FulltextSearchable add custom fields

I need a custom field to be FulltextSearchable. Therefore I tried this code as described in the FulltextSearchable class:
Object::add_extension('Page', "FulltextSearchable('SearchableContent')");
then run dev/build.
Basically Fulltext Search seems to work. But the content of the custom Field 'SearchableContent' seems never to be checked.
Of course I enabled FulltextSearch first by:
FulltextSearchable::enable();
Thx,
Florian
All SiteTree classes have their search columns define in FulltextSearchable like:
$defaultColumns = array(
'SiteTree' => '"Title","MenuTitle","Content","MetaTitle","MetaDescription","MetaKeywords"',
'File' => '"Title","Filename","Content"'
);
so I don't think SilverStripe will pick up on your extra column. Unless you edit the FulltextSearchable but that's probably a bad idea... or just create a custom search function like for plain DataObject so you can specify exactly which columns to search on:
silverstripe dataobject searchable