TCA Icon overlay in typo3 backend - typo3

I’m working on an extension where I synchronise some data to another database and I wanted to show this in the backend using a TCA icon overlay. Sadly I could not find out how to do this. I thought about using ‘ctrl’=>‘typeicon_classes’ (using the state field of my table to choose an icon), this works for the default (non synchronised element) but I cannot figure out how to set an overlay. Any idea on how to do this?
My TCA configuration looks like this:
'ctrl' => [
...
'typeicon_column' => 'state',
'typeicon_classes' => [
'new' => 'mimetypes-x-content-login',
'synced' => 'mimetypes-x-content-login-overlay-approved',
]
],
The "synced" part does not work as expected. What I would expect is to either add the overlay at the end of the icon or by adding it with a whitespace but both did not work.
Any help is appreciated.
PS: I really just need this in the TYPO3 backend, the obvious solution for frontend is to use fluid or PHP but I don't think this suits the TYPO3 Backend list.

You need to register your icon files.
Given your icon files are named content_login.svg and content_login_overlay_approved.svg located in directory /Resources/Public/Icons/ you can register these in ext_localconf.php as following:
if (TYPO3_MODE === 'BE') {
$icons = [
'mimetypes-x-content-login' => 'content_login.svg',
'mimetypes-x-content-login-overlay-approved' => 'content_login_overlay_approved.svg',
];
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
foreach ($icons as $identifier => $path) {
$iconRegistry->registerIcon(
$identifier,
\TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
['source' => 'EXT:YOUREXTENSIONNANME/Resources/Public/Icons/' . $path]
);
}
}
Adapt yourextensionname

Related

How do I hide a drupal 8 form element on default

I am trying to do something that should be extremely easy in drupal. I just want to simply hide a form field in the drupal admin by default.
Making the field disabled simply doesn't work. I cannot find any documentation for this. It's unbelievable that it's this hard to do something so simple in Drupal.
$form['field_name']['#states'] = [
'visible' => [
':input[name="field_foo[0][target_id]"]' => ['value' => 'blah'],
],
'invisible' => true,
];
The visible part works. If another field has a certain value, then show the form element.
But I simply cannot get it to hide this field on default when you're adding a new node.
Add into form element array $element = ['#access' => FALSE,]:
$form['field_name'] = [
'#access' => FALSE,
]
Easy and does not affect your default value (if default is set):
$form['field_name']['#attributes']['class'][] = 'hidden';
Drupal core will "display: none;" this element from core styles using the 'hidden' css class.
You don't need to set invisible, it will be hidden by default unless the visible condition is met. Also the input looks to be wrong, as it should be whatever the name attribute is set to in the element you are basing the condition on.
The drupal.org documentation with an example.
e.g.
$form['field_name']['#states'] = [
'visible' => [
':input[name="field_conditional_on"]' => ['value' => 'value_conditional_on'],
],
];
Or if you just want to hide it using CSS's display property, you could use something like below,
$form['field_name']['#states'] = [
'#attributes' => array('style' => array('display: none;')),
];

TYPO3: Using ###PAGE_TSCONFIG_ID### with addRecord in TCA

The problem at hand has to do with the TCA and its addRecord option, which should save new records to a specific pid configured by ###PAGE_TSCONFIG_ID###. (TYPO3 8.7.24, php 7.2)
The websites extension has a tx_rwfm_domain_model_websitecategory and a tx_rwfm_domain_model_website table, related via a m:m table. The idea is to create website categories and then collect websites, which are assigned to a category. In the BE, the categories (pid=24) as well as the websites (pid=12) have their own folder in the site tree. websitecategory has a multiSelectField to easily select websites and assign them to the category in question. And also "website" has a multiSelectField for categories to easily assign a website to multiple categories.
So far everything is working fine.
Now I bump into this scenario:
I want to add websites to the categories, so I open the websitecategory folder page in list view.
I now realise that the website I want to add has not yet been created.
Instead of closing the websitecategory page, I click on "addRecord" next the multiSelectField of websites (m:m connection)
A new window opens to create the new website, "save and close" brings me back to the websitecategory page, where I can see that the new website was added to the selection list.
The point is: The new website has to be created in its own folder page (pid=12) and NOT on the websitecategory page (pid=24). To do so, there is the property ###PAGE_TSCONFIG_ID###, which I try to configure like this:
// TCA of websitecategory
return [
[...],
'columns' => [
'websites' => [
'config' => [
'type' => 'select',
'renderType' => 'selectMultipleSideBySide',
'enableMultiSelectFilterTextfield' => true,
'foreign_table' => 'tx_rwfm_domain_model_website',
'foreign_table_where' => 'AND tx_rwfm_domain_model_website.sys_language_uid IN (-1,0) ORDER BY tx_rwfm_domain_model_website.title ASC',
'MM' => 'tx_rwfm_domain_model_website_websitecategory_mm',
'MM_opposite_field' => 'categories',
'fieldControl' => [
'editPopup' => [...],
'addRecord' => [
'disabled' => false,
'options' => [
'setValue' => 'prepend',
'title' => 'Create a new website record',
'table' => 'tx_rwfm_domain_model_website',
'pid' => '###PAGE_TSCONFIG_ID###',
],
],
]
]
]
[...]
]
Following the documentation https://docs.typo3.org/typo3cms/TSconfigReference/8.7/PageTsconfig/TCEform/Index.html?highlight=page_tsconfig_id I add this to my page TSconfig:
// TSconfig
TCEFORM {
tx_rwfm_domain_model_website {
pid.PAGE_TSCONFIG_ID = 12
}
tx_rwfm_domain_model_websitecategory {
pid.PAGE_TSCONFIG_ID = 28
}
}
Unfortunately, this does not work. Instead, TYPO3 tries to add it to [root_level] 0, where the table is not allowed.
However, if I replace ###PAGE_TSCONFIG_ID### in TCA -> addRecord with the hard-coded value of the pid, 12, the website is indeed saved on the proper page folder with pid 12.
How do I have to configue TSconfig to make the saving process work propertly?
Using pid as a table reference before the constant PAGE_TSCONFIG_ID is most likely the wrong field you want to address. So this:
TCEFORM {
tx_rwfm_domain_model_website {
pid.PAGE_TSCONFIG_ID = 12
}
tx_rwfm_domain_model_websitecategory {
pid.PAGE_TSCONFIG_ID = 28
}
}
should become this:
TCEFORM {
tx_rwfm_domain_model_website {
[field_of_related_table].PAGE_TSCONFIG_ID = 12
}
tx_rwfm_domain_model_websitecategory {
[field_of_related_table].PAGE_TSCONFIG_ID = 28
}
}
as far as I read the source code, this only applies to values defined in foreign_table_where.
After fooling around quite some time (actually years!), it finally has become clear to me, that the field you need to assign the PID_TSCONFIG_ID to has to be the one, that acts as the pivot to the m:m relation. Or: the opposite field. The even more confusing thing about that is, that, by definition, the opposite field must only be defined on one side of the relationship. So for the "other side" you need to look at the related table's name and use that one.
In the above example that would mean, that categories has to be used instead of pid:
// TSconfig
TCEFORM {
tx_rwfm_domain_model_website {
categories.PAGE_TSCONFIG_ID = 12
}
tx_rwfm_domain_model_websitecategory {
websites.PAGE_TSCONFIG_ID = 28
}
}
That way, records get saved to their given page ids. Thanks, TYPO3, for providing such a mysterious documentation on that topic! :-(
Will try to improve the docu in that aspect ASAP.

What's the best way to site specific configuration in a multisite TYPO3 installation?

We have a TYPO3 9.5 installation with a bunch of different websites in it.
We want to store some custom configurations for each site (eg. show phone number in footer yes/no and something like this) and give the editors the possibility to change this in a simple way in the backend.
It would be nice if we can store these properties on the rootpage of each site but be able to overwrite (some) properties on sub pages if needed.
Similar to the page properties that fluidtypo3/flux brings.
Is there a possibility to achieve this with TYPO3 core and a custom extension? Eg. by extending the page table or adding custom table?
You need to differ between a site configuration and regular pages!
The site configuration is valid for the full site, so for every page
A page can be different on a page level
Both use cases are valid, so let's explain in detail
Extending the site configuration
The site configuration can easily be extended by creating the file <site-extension>/Configuration/SiteConfiguration/Overrides/sites.php
<?php
defined('TYPO3_MODE') || die('Access denied.');
call_user_func(
function ($table) {
$GLOBALS['SiteConfiguration'][$table]['columns']['trackingCode'] = [
'label' => 'Label',
'config' => [
'type' => 'input',
'eval' => 'trim',
'placeholder' => 'GTM-123456',
],
];
$GLOBALS['SiteConfiguration'][$table]['types']['0']['showitem'] .= ',--div--;Extra,trackingCode';
},
'site'
);
The value of the new field trackingCode can then be easily fetched, e.g. by TS with data = site:trackingCode. As an alternative you can also use the SiteProcessor to get access to the site configuration in a FLUIDTEMPLATE.
Extending pages
Create the file <site-extension>/Configuration/TCA/Overrides/pages.php
<?php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'pages',
[
'trackingCode' => [
'exclude' => true,
'label' => 'A label',
'config' => [
'type' => 'input',
]
],
]
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'pages',
'--div--;Extra, trackingCode'
);
and `ext_tables.sql``
CREATE TABLE pages (
trackingCode text NOT NULL
);
and you get access to the field with TypoScript and within FLUIDTEMPLATE with {data.trackingCode}.
Using slide
By adding trackingCode to the comma separated list in [FE][addRootLineFields] (use the Install Tool > Settings > Configure Installation-Wide Options it is possible to override the value for all subpages.
The following TypoScript will get up the rootline and return the 1st value set.
lib.code = TEXT
lib.code.data = levelfield:-1,trackingCode, slide

Mask and issues

Regarding the mask, in backend mask have default configurations such as below:
general.json => typo3conf/mask.json
frontend.content => fileadmin/templates/content/
frontend.layouts => fileadmin/templates/content/Layouts/
frontend.partials => fileadmin/templates/content/Partials/
backend.backend => fileadmin/templates/backend/
backend.layouts_backend => fileadmin/templates/backend/Layouts/
backend.partials_backend => fileadmin/templates/backend/Partials/
backend.preview => fileadmin/templates/preview/
While installing our theme extension, we need to change the above mask configuration option values like below:
general.json => typo3conf/ext/<extension_key>/mask.json
frontend.content => fileadmin/<extension_key>/templates/content/
frontend.layouts => fileadmin/<extension_key>/templates/content/Layouts/
frontend.partials => fileadmin/<extension_key>/templates/content/Partials/
backend.backend => fileadmin/<extension_key>/templates/backend/
backend.layouts_backend => fileadmin/<extension_key>/templates/backend/Layouts/
backend.partials_backend => fileadmin/<extension_key>/templates/backend/Partials/
backend.preview => fileadmin/<extension_key>/templates/preview/
We tried like below, but its not working:
plugin.tx_mask.general.json = EXT:user_ss4u/mask.json
module.tx_mask.general.json = EXT:user_ss4u/mask.json
It seems like you try to override the settings via typoscript, which is -
as far as i know - not possible.
The settings you want to change are saved in typo3conf/LocalConfiguration.php
in ['EXT']['extConf']['mask'] so there are two (okay, one with two ways) possibilities to change them:
1.1 via Extension Manager
Open the module "Extension" in the TYPO3 Backend and search for the mask Extension.
Click on the configure icon at the end of the row.
Now you should be able to change the settings.
Changes are stored in typo3conf/LocalConfiguration.php
1.2 via Mask itself
Open the module "Mask" in the TYPO3 Backend.
Click on the configure icon to change to the Configuration Tab.
Now you should be able to change the settings.
Changes are stored in typo3conf/LocalConfiguration.php
2. via PHP
You can add the following snippet to a file like the ext_localconf.php in typo3conf/ext/<extension_key> or in typo3conf/AdditionalConfiguration.php
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['mask'] = serialize([
'json' => 'typo3conf/ext/<extension_key>/mask.json',
'content' => 'fileadmin/<extension_key>/templates/content/',
'layouts' => 'fileadmin/<extension_key>/templates/content/Layouts/',
'partials' => 'fileadmin/<extension_key>/templates/content/Partials/',
'backend' => 'fileadmin/<extension_key>/templates/backend/',
'layouts_backend' => 'fileadmin/<extension_key>/templates/backend/Layouts/',
'partials_backend' => 'fileadmin/<extension_key>/templates/backend/Partials/',
'preview' => 'fileadmin/<extension_key>/templates/preview/',
]);

Adding new checkbox field to tx_news_domain_model_media

I am trying to add a new checkbox field 'showinhome' to the table 'tx_news_domain_model_media' same to the field 'showinpreview' here is my TCA Configuration in Configuration/TCA/Overrides/tx_news_domain_model_media.php
$temporaryColumns = [
'showinhome' => [
'exclude' => 1,
'label' => 'Show in Home',
'config' => [
'type' => 'check',
'default' => 0,
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tx_news_domain_model_media',
$temporaryColumns
);
$GLOBALS['TCA']['tx_news_domain_model_media']['ctrl']['label_alt'] .= ', showinhome';
$GLOBALS['TCA']['tx_news_domain_model_media']['interface']['showRecordFieldList'] .= ', showinhome';
$GLOBALS['TCA']['tx_news_domain_model_media']['palettes']['newsPalette']['showitem'] .= 'showinhome,';
The field is not displayed, can someone help me please?
You have mixed up some stuff here.
First: tx_news can use either the own media model or the native FAL relations. I personally always use the native FAL relation.
If you want to add this field to the media table, then there is no newsPalette there. You can use the below code to add the new field:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tx_news_domain_model_media', $temporaryColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tx_news_domain_model_media', implode(',', array_keys($temporaryColumns)));
If you using the normal FAL relation then the showinpreview field is added to the sys_file_reference table's TCA configuration and not to the tx_news_domain_model_media table.
If you want to add this field to the file, then you need to add it to the sys_file_reference field the same way tx_news does it (I guess that you already copied the code from it's override file)
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file_reference', $temporaryColumns);
// add special news palette
$GLOBALS['TCA']['sys_file_reference']['palettes']['newsPalette']['showitem'] .= ', showinhome';
Last but not least: you have to specify tx_news as a dependency in your extension, otherwise TYPO3 does not know that your extension has to be loaded after tx_news. If you change the dependency after you installed your extension you probably need to uninstall and install it again in the extension manager.