I have a question about enablecolumns and QueryBuilder in TYPO3 9.5:
In the TCA I defined the enablecolumns:
'ctrl' => [
'title' => '....'
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'versioningWS' => 2,
'versioning_followPages' => true,
'origUid' => 't3_origuid',
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l18n_parent',
'transOrigDiffSourceField' => 'l18n_diffsource',
'delete' => 'deleted',
'enablecolumns' => [
'disabled' => 'hidden',
'fe_group' => 'fe_group',
],
]
In the repository I create a custom Query:
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_myext_domain_model_table');
$result = $queryBuilder
->select('*')
->from('tx_myext_domain_model_table')
->where($where)
->execute();
If I debug the SQL with
$queryBuilder->getSQL();
I see the deleted, and hidden conditions but no fe_group
If I add
$queryBuilder
->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(FrontendGroupRestriction::class))
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(HiddenRestriction::class));
before the execution of the query, the fe_groups condition ist added.
What am I missing?
Thank you
Christian
This is because the QueryBuilder by default uses the DefaultRestrictionContainer which adds only the following restrictions:
protected $defaultRestrictionTypes = [
DeletedRestriction::class,
HiddenRestriction::class,
StartTimeRestriction::class,
EndTimeRestriction::class
];
References:
https://github.com/TYPO3/TYPO3.CMS/blob/9.5/typo3/sysext/core/Classes/Database/Query/QueryBuilder.php#L86
https://github.com/TYPO3/TYPO3.CMS/blob/9.5/typo3/sysext/core/Classes/Database/Query/Restriction/DefaultRestrictionContainer.php#L28-L33
What you're probably looking for is the FrontendRestrictionContainer which uses the following default restrictions:
protected $defaultRestrictionTypes = [
DeletedRestriction::class,
FrontendWorkspaceRestriction::class,
HiddenRestriction::class,
StartTimeRestriction::class,
EndTimeRestriction::class,
FrontendGroupRestriction::class,
];
Reference: https://github.com/TYPO3/TYPO3.CMS/blob/9.5/typo3/sysext/core/Classes/Database/Query/Restriction/FrontendRestrictionContainer.php#L33-L40
A possible solution would be to use this container instead of the default one:
$container = GeneralUtility::makeInstance(FrontendRestrictionContainer::class);
$queryBuilder->setRestrictions($container);
Related
I want to update an extension from TYPO3 v7 to v9. In v7 is it possible to add an ADD-Wizard to a select field in the TCA:
'wizards' => array(
'_PADDING' => 2,
'_VERTICAL' => 1,
'add' => Array(
'type' => 'script',
'title' => 'Create new record',
'icon' => 'add.gif',
'params' => Array(
'table'=>'myTable',
'pid' => '###CURRENT_PID###',
'setValue' => 'prepend'
),
'module' => array(
'name' => 'wizard_add',
)
),
),
in TYPO3 9 this does not work anymore. I the manual i cannot find anything to the TCA wizards anymore since version 8.
Are they gone, or is there an other way to achive the same?
Thanks!
You need to migrate to fieldControl used since TYPO3v8 and newer.
'fieldControl' => [
'addRecord' => [
'disabled' => false,
'options' => [
'table' => 'myTable',
'setValue' => 'prepend',
],
],
],
This is my TCA field configuration
'membership_type' => [
'exclude' => 0,
'label' => $ll . '/locallang_db.xlf:my_label.type',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'sys_category',
'foreign_table_where' => ' AND sys_category.parent=' . $membershipTypeParent . ' AND (sys_category.sys_language_uid = 0 OR sys_category.l10n_parent = 0) ORDER BY sys_category.sorting ASC',
'items' => [
[$llg . 'fe_users.groups.unkonwn', 0]
],
],
],
I want this field to be required. I tried setting:
['config']['eval'] = 'required';
['config']['minitems'] = 1;
But none of them seem to do the job. I found also this old thread on typo3 forge which says it is not possible https://forge.typo3.org/issues/60247. I am using TYPO3 8 now.
"Eval does not exist for select fields. However, what you're missing is a field to choose a non-empty value.
I suggest you use a multi-select with two selects (similar to fe_group in pages) where you can only select one item)."
I would prefer to stay with single select instead of multi-select. Is that possible ?
Eval does exist for select fields, there will be something incorrect in your configuration.
Here's an example I made which works
'exampleSelectSingle' => array(
'label' =>'Select Single',
'exclude' => 0,
'config' => array(
'type' => 'select',
'renderType' => 'selectSingle',
'eval' => 'required',
'items' => array(
['Empty',''],
['Label 1','value1'],
['Label 2','value2']
)
),
'size' => 1,
'minitems' => 1
)
This renders correctly with the first (empty) option selected, which triggers the validation:
https://i.stack.imgur.com/EXbdC.png
I have TYPO3 version 7.6.18.
'images' => [
'label' => 'LLL:EXT:fefiles/Resources/Private/Language/locallang_db.xlf:images',
'config' => [
'type' => 'inline',
'foreign_table' => 'tx_fefiles_domain_model_photo',
'foreign_field' => 'album',
'foreign_table_where' => 'AND tx_fefiles_domain_model_photo.allow = 1',
'maxitems' => '5000'
],
],
This is configuration in TCA for someone field.
in table tx_fefiles_domain_model_photo I have 4 rows which id = album,
but allow = 1 only two. But I get all four rows. My condition tx_fefiles_domain_model_photo.allow = 1 does't works. I tried different variants, cleared cache. Really I need your help, I must make it works, help me please (
Try:
'foreign_match_fields' => [
'allow' => 1
]
instead of foreign_table_where.
For examples look into documentation: https://docs.typo3.org/typo3cms/TCAReference/
I am using TYPO3 7.6.11.
I wrote an provider extension to add some ts-code, templates, and viewhelpers.
After that, I wanted to add a custom data record (to use in the Backend).
I added the table in the ext_tables.sql.
I have a TCA-config under /[extension]/Configuration/TCA/tablename.php
I added
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tablename');
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToInsertRecords('tablename');
to my ext_tables.php
Did I miss something?
I get a new record type under "System Records" in the List Module. I can add such an record, and the TCA-config seems to work fine for the record form.
But after saving, I have no record in the list view. The DB is looking fine. The record is saved correctly in my new table. What am I doing wrong?
Thanks
Edit:
crtl:
'ctrl' => array (
'title' => 'LLL:EXT:svkcore/Resources/Private/Language/locallang.xlf:records.title',
'label' => 'title',
'label_alt' => '',
'label_alt_force' => TRUE,
'default_sortby' => 'ORDER BY datetime DESC',
'prependAtCopy' => 'LLL:EXT:lang/locallang_general.php:LGL.prependAtCopy',
'versioningWS' => TRUE,
'versioning_followPages' => TRUE,
'origUid' => 't3_origuid',
'shadowColumnsForNewPlaceholders' => 'sys_language_uid,l18n_parent,starttime,endtime,fe_group',
'dividers2tabs' => TRUE,
'useColumnsForDefaultValues' => 'type',
'transOrigPointerField' => 'l18n_parent',
'transOrigDiffSourceField' => 'l18n_diffsource',
'languageField' => 'sys_language_uid',
'crdate' => 'crdate',
'tstamp' => 'tstamp',
'delete' => 'deleted',
'type' => 'type',
'cruser_id' => 'cruser_id',
'editlock' => 'editlock',
'enablecolumns' => array (
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
'fe_group' => 'fe_group',
),
'typeicon_column' => 'type',
'typeicons' => array (
'1' => 'EXT:svkcore/res/gfx/svkcore_inturl.gif',
'2' => 'EXT:svkcore/res/gfx/svkcore_exturl.gif',
),
'thumbnail' => 'image',
'iconfile' => 'EXT:svkcore/res/gfx/ext_icon.gif',
'searchFields' => 'uid,title,short,bodytext'),
'interface' => Array (
'showRecordFieldList' => 'title,hidden,datetime_start,starttime,archivedate,category,short,image,record_files'
),
Since Typo3 7 it is possible to mask the list-view. This is configured via PageTSConfig, have a look at your info-Module (select the correct page in the page tree) and check the TSConfig there.
The configuration can be found in the following path:
mod.web_list.allowedNewTables
Check in ext_tables.php if you have everything needed for your new table : Typoscript inclusion, language file, exemple :
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'My TS configuration');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_myext_domain_model_mytable', 'EXT:my_ext/Resources/Private/Language/locallang_csh_tx_myext_domain_model_mytable.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_myext_domain_model_mytable');
Are you sure the new records are stored in the current page : have a look at the TS "persistence.storagePid".
You can check in the database wich pid is used for your new records.
Regards,
Florian
If I try to extend fe_user table by creating a new Model Object on extension builder in Typo3 6.1.7, it overwrites TCA by writing those lines in ext_tables.php of my extension:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('fe_users', 'EXT:voiwizard/Resources/Private/Language/locallang_csh_fe_users.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('fe_users');
$TCA['fe_users'] = array(
'ctrl' => array(
'title' => 'LLL:EXT:voiwizard/Resources/Private/Language/locallang_db.xlf:fe_users',
'label' => 'prova',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'dividers2tabs' => TRUE,
'versioningWS' => 2,
'versioning_followPages' => TRUE,
'origUid' => 't3_origuid',
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
),
'searchFields' => 'prova,',
'dynamicConfigFile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Configuration/TCA/User.php',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY) . 'Resources/Public/Icons/fe_users.gif'
),
);
This code overwrites the original fe_users's TCA configuration and the back-end [website user][1] table becomes inaccessible.
Is there any way to prevent this or do I have to delete those lines every time I want to save the changes in the extension builder?
I've found an error in my relationship:
To properly extend fe_users table with a Model Object in Extension Builder, I had to "extend existing model class" \TYPO3\CMS\Extbase\Domain\Model\FrontendUser instead of "map to existing table" fe_users.
In this way, everything works as expected!