TYPO3 FlexForm: how to disable field in inline element? - typo3

I have a TYPO3 plugin with a FlexForm. In the FlexForm I added relations to a foreign table. I now need to disable some of the fields of the foreign table. I can't do this via user rights since it's a question of context, not rights.
My FlexForm looks like this:
<settings.moreinfo>
<TCEforms>
<label>my label</label>
<config>
<type>inline</type>
<foreign_table>tx_foo_domain_model_bar</foreign_table>
<foreign_field>content_uid</foreign_field>
<foreign_sortby>sorting</foreign_sortby>
<maxitems>50</maxitems>
</config>
</TCEforms>
</settings.moreinfo>
I thought about TCEFORM, but have no idea how to address the field:
TCEFORM.tt_content.pi_flexform.foobar.general {
settings\.moreinfo {
# maybe here?
}
}
Is there any possibility to disable a field via TSconfig or PHP?

in general you could disable flexform fields. the manual states the possibility:
Other properties also apply to flex form fields, in this case the full property path including the data structure key has to be set:
TCEFORM.[tableName].[fieldName].[dataStructureKey].[flexSheet].[flexFieldName].[propertyName].
The [dataStructKey] represents the key of a FlexForm in
$GLOBALS['TCA'][<tableName>]['columns'][<field>]['config']['ds']. This
key will be split into up to two parts. By default the first part will
be used as identifier of the FlexForm in TSconfig. The second part
will override the identifier if it is not empty, list or *.
For example the identifier of the key my_ext_pi1,list will be my_ext_pi1
and of the key *,my_CType it will be my_CType. See section Pointing to
a data structure of the TCA reference for details.
Some properties apply to whole FlexForm sheets, their property path is
TCEFORM.[tableName].[fieldName].[dataStructureKey].[flexSheet].[propertyName].
it could be problematic if you use . inside of identifiers.

This answer to a different question inspired me to the solution which finally solved my problem!
foreign_types was the solution I was looking for:
<settings.moreinfo>
<TCEforms>
<label>my label</label>
<config>
<type>inline</type>
<foreign_table>tx_foo_domain_model_bar</foreign_table>
<foreign_field>content_uid</foreign_field>
<foreign_sortby>sorting</foreign_sortby>
<maxitems>50</maxitems>
<foreign_types type="array">
<numIndex index="1" type="array">
<showitem>
title, link, --div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access, hidden;;1, starttime, endtime
</showitem>
</numIndex>
</foreign_types>
</config>
</TCEforms>
</settings.moreinfo>

Related

Prefill a flexform's value via TSConfig?

How do I prefill a plugin's flexform value via TSConfig?
The goal is that when a user creates a new CE with that flexform, that field is already filled in.
This is how the field looks in the flexform.
<settings.fal.storage>
<TCEforms>
<label>LLL:EXT:fileviews/Resources/Private/Language/locallang_flexform.xlf:fileviews.falStorage</label>
<config>
<type>group</type>
<internal_type>db</internal_type>
<allowed>sys_file_storage</allowed>
<size>1</size>
<default>1</default>
<maxitems>1</maxitems>
<minitems>1</minitems>
</config>
</TCEforms>
</settings.fal.storage>
I want to predefine it to storage n. We tried this code in Page TSConfig, but no luck yet.
TCEFORM {
tt_content {
pi_flexform {
fileviews_allfilesteaser {
sDEF {
settings\.fal\.storage.default = 1
}
}
}
}
}
Or maybe use TCADefaults?
You missed one level. default is not available directly below [propertyName]. There, only the documented properties are available.
Also below config, there are only limited configuration options available (see TSconfig Reference):
TCEFORM.[tableName].[fieldName].[dataStructureKey].[flexSheet].[flexFieldName].config.[configurationOption] = ...

TYPO3: Default setting in TCA overwritten when settable via Flexforms in Extbase Extension

I added the possibility to set a detailPid in my Extension via flexforms:
<ROOT>
<type>array</type>
<el>
<settings.detailPid>
<TCEforms>
<label>
LLL:EXT:events/Resources/Private/Language/locallang_db.xlf:flexforms.overview.detailPid
</label>
<config>
<type>group</type>
<internal_type>db</internal_type>
<allowed>pages</allowed>
<size>1</size>
<maxitems>1</maxitems>
<show_thumbs>1</show_thumbs>
<wizards>
<suggest>
<type>suggest</type>
</suggest>
</wizards>
</config>
</TCEforms>
</settings.detailPid>
</el>
</ROOT>
I want to set the default detailPid via TS in my setup.ts:
plugin.tx_events_eventdetail {
settings {
listPid = {$plugin.tx_events_eventdetail.settings.listPid}
detailPid = {$plugin.tx_events_eventdetail.settings.detailPid}
}
}
My problem is, that if I don't configure a detailPid in my plugin, the default value from my TS is not used. The settings.detailPid in my Controller or in the FLUID-Template is empty. Is there a way to just fix that?
I already looked around and found out, that the news-extension has the same behavior.
Thanks for any help and suggestions!
At least the extensions tt_address and news have a configuration which allow a fallback to TS if flexform is empty. If you need that, you can copy the code and use that in your extension.
There is no configuration available in the core for that.
You can rename your flexforms detailPid path to something like settings.flexform.detailPid then in your controller you may merge the settings from TS with those from the Flexform so that only non empty values will take affect.
ArrayUtility::arrayMergeRecursiveOverrule($this->settings, $this-settings['flexform'])
https://api.typo3.org/typo3cms/current/html/class_t_y_p_o3_1_1_c_m_s_1_1_extbase_1_1_utility_1_1_array_utility.html#af4008bc539411e9114ed53b1b007735b

Get sys_categories from tt_content flexform settings

Let's say I have a FE Plugin with the option to set some sys_category references via the following flexform field:
<settings.categories>
<TCEforms>
<label>Some Label</label>
<config>
<type>select</type>
<foreign_table>sys_category</foreign_table>
<foreign_table_where> AND sys_category.sys_language_uid IN (-1, 0) ORDER BY sys_category.sorting ASC</foreign_table_where>
<MM>sys_category_record_mm</MM>
<MM_opposite_field>items</MM_opposite_field>
<MM_match_fields>
<tablenames>tt_content</tablenames>
<fieldname>categories</fieldname>
</MM_match_fields>
<maxitems>9999</maxitems>
<renderMode>tree</renderMode>
<size>10</size>
<treeConfig>
<appearance>
<expandAll>1</expandAll>
<showHeader>1</showHeader>
</appearance>
<parentField>parent</parentField>
</treeConfig>
</config>
</TCEforms>
</settings.categories>
Now I want to get all category Objects referenced in the flexform in the controller of the plugin. What's the best approach to do so? Should’nt there already be a suitable repository function somewhere? Thank you for your help!
There is no dedicated API for that, however normally you wouldn't need the mm-relation. Removing that and having it like
<settings.categories>
<TCEforms>
<label>LLL:EXT:news/Resources/Private/Language/locallang_be.xlf:flexforms_general.categories</label>
<config>
<type>select</type>
<renderMode>tree</renderMode>
<renderType>selectTree</renderType>
<treeConfig>
<dataProvider>GeorgRinger\News\TreeProvider\DatabaseTreeDataProvider</dataProvider>
<parentField>parent</parentField>
<appearance>
<maxLevels>99</maxLevels>
<expandAll>TRUE</expandAll>
<showHeader>TRUE</showHeader>
<width>600</width>
</appearance>
</treeConfig>
<foreign_table>sys_category</foreign_table>
<foreign_table_where>AND (sys_category.sys_language_uid = 0 OR sys_category.l10n_parent = 0) ORDER BY sys_category.sorting</foreign_table_where>
<size>15</size>
<minitems>0</minitems>
<maxitems>99</maxitems>
</config>
</TCEforms>
</settings.categories>
it is much easier to retrieve the categories. You can also take a look at the CategoryRepository I am using for the news extension https://github.com/georgringer/news/blob/master/Classes/Domain/Repository/CategoryRepository.php

switchable controller action is not working TYPO3 7.6

Hi I have an extension in TYPO3 7.6. I have two actions list and show. In my flexform there is a switchable controller action.list action is working. But show action not working. Please check my code.
Flexform
<switchableControllerActions>
<TCEforms>
<label>Display Type</label>
<onChange>reload</onChange>
<config>
<type>select</type>
<items type="array">
<numIndex index="1" type="array">
<numIndex index="0">List</numIndex>
<numIndex index="1">News->list</numIndex>
</numIndex>
<numIndex index="2" type="array">
<numIndex index="0">Detail</numIndex>
<numIndex index="1">News->show</numIndex>
</numIndex>
</items>
<minitems>0</minitems>
<maxitems>1</maxitems>
<size>1</size>
</config>
</TCEforms>
</switchableControllerActions>
list view
<f:if condition="{news}">
<ul>
<f:for each="{news}" as="item">
<li>
<f:link.action action="show" controller="News" arguments="{news:'{item}'}" noCacheHash="false" pageUid="{settings.detailPid}" >
{item.title}
</f:link.action>
</li>
</f:for>
</ul>
</f:if>
I selected list from configuration in list page and select detail from detail page. List is working perfectly but detail is not working.
Try to add arguments like this:
arguments="{news: item.uid}"
in showAction you can get argument like this:
$newsId = $this->request->getArgument('news');
$news = $this->newsRepository->findByUid($newsId);
$this->view->assign('news', $news);
It will work perfectly as you required.
Not gtting any error message.only a blank page is shown
You might want to change that first
check your error_reporting on php level (display_errors)
set your Environment to Development (you can select the preset in the install tool)
Look Debug options up in the install tool (all configuration)
Keep in mind, that you dont want to make those adjustments in Production Environment.
Then you should be able to see the error.
I selected list from configuration in list page and select detail from
detail page. List is working perfectly but detail is not working.
Did you add the show action to the plugin configuration? Look that up in your extensions ext_localconf.php
Look for this call:
ExtensionUtility::configurePlugin
Your Controller->action combinations have to exist in the first array parameter you pass. That might look like:
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Vendor.ext_key',
'News',
array(
'News' => 'list,show'
)
);
If you pass a 4th parameter with Controller->action combinations (like the other), you can define actions, that should not be cached. You would use such to configure form actions or filterable result-lists.
note: Allways use the full namespace in ext_localconf.php and other bootstrap files, if you make use of "use" statements you might have another fatal error, typo3 concatenates all those bootstrap files.
Also - you could have misunderstood the switchableControllerActions pattern. If you want one plugin (the ce) to show both actions, the option has to be
<switchableControllerActions>
<TCEforms>
...
<config>
<type>select</type>
<items type="array">
...
<numIndex index="3" type="array">
<numIndex index="0">List with Details</numIndex>
<numIndex index="1">News->list;News->show</numIndex>
</numIndex>
</items>
...
</config>
</TCEforms>
</switchableControllerActions>
The selected option will be saved in the xml datastructure and is used as configuration, so if only one action is available for this instance then you will receive an error.
If you use different content elements to show the list and detail view you have to select the correct switchableControllerAction option in both content elements.

Typo3 7 Extbase Actions FlexForm

I using the Typo3 7.6.10 Extbase Builder.
I have a created an extension and a have a model with one controller.
In my controller i have 2 actions. list(); searchbar();
Now i want to choose in the backend when im adding the plugin which action to start! I can't manage to do this option.
I heard about the FlexForm Options and switchableControllerActions.
But i can't manage to do this. The Documentation is bad https://wiki.typo3.org/Extension_Development,_using_Flexforms#Create_Your_Extension
For Example: t3lib_extMgm is deprecated
Is there a valid example how to do this?
Create an .xml file. I know of no convention, but it's a good idea to name the file the same as your plugin, because you need separate files for each plugin type of your extension.
typo3conf/ext/extensionkey/Configuration/FlexForms/Pluginname.xml
The xml file needs to contain at least a TCEform structure with the key switchableControllerActions as a select type option, like so.
<?xml version="1.0" encoding="UTF-8"?>
<T3DataStructure>
<sheets>
<general>
<ROOT>
<TCEforms>
<sheetTitle>Display type</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<switchableControllerActions>
<TCEforms>
<label>Display</label>
<config>
<type>select</type>
<items type="array">
<numIndex index="1" type="array">
<numIndex index="0">List</numIndex>
<numIndex index="1">Controller->list</numIndex>
</numIndex>
<numIndex index="2" type="array">
<numIndex index="0">Search bar</numIndex>
<numIndex index="1">Controller->searchbar</numIndex>
</numIndex>
</items>
</config>
</TCEforms>
</switchableControllerActions>
</el>
</ROOT>
</general>
</sheets>
</T3DataStructure>
Next, make the Flexform known in the Backend by registering the file. Make note of the $pluginSignature variable. It must match the pattern of extension_pluginname. You'll have to define the plugin name accordingly.
// Register FlexForm Configuration
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['extension_plugin'] = 'pi_flexform';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
'extension_plugin',
'FILE:EXT:extensionkey/Configuration/FlexForms/Pluginname.xml'
);
In the example above, replace "extension_plugin" and "extensionkey" accordingly.
Lastly, flush the system cache and you should be good to go. The configuration option should turn up in the plugins settings. The switchableControllerActions value defined should then replace your standard action for the plugin instance.
There are, however, a few more things to point out: Note, that the actions you define replaces the allowed cacheableControllerAction combination. So, if your extension has, for extample, another action show() for this plugin instance, that one needs to be appended like so:
<numIndex index="1" type="array">
<numIndex index="0">List</numIndex>
<numIndex index="1">Controller->list;Controller->show</numIndex>
</numIndex>