Adding new checkbox field to tx_news_domain_model_media - typo3

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.

Related

how to extend the metadata in TYPO3 10.4.13

I am trying to add a description field under the page properties/metadata which was still present in the TYPO3 8.7.32 version.
I have also already tried in the setup with the following code:
page.meta.description.field = description
#page.meta.description.ifEmpty =
currently it looks like this
and should look like this
If your goal is to add a SEO description field, this field is already available in the SEO tab.
Nevertheless, if you want to add a new field in metadata, you have to :
Add the new field in : your_ext/ext_tables.sql
CREATE TABLE pages (
new_field varchar(255) DEFAULT '' NOT NULL
);
Override the TCA : create or update the file your_ext/Configuration/TCA/Overrides/pages.php
<?php
defined('TYPO3_MODE') or die();
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
call_user_func(static function () {
// Define new TCA field
$additionalFields = [
'new_field' => [
'exclude' => false,
'l10n_mode' => 'prefixLangTitle',
'label' => 'LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:pages.your_ext',
'description' => 'LLL:EXT:your_ext/Resources/Private/Language/locallang_db.xlf:pages.your_ext.description',
'config' => [
'type' => 'input',
'size' => 60,
'max' => 255
]
]
];
// Add the new TCA columns
ExtensionManagementUtility::addTCAcolumns('pages', $additionalFields);
// Add the field to the palette
ExtensionManagementUtility::addFieldsToPalette('pages', 'metatags', 'new_field', 'after:keywords');
});
Then you have to update the DB with BE module Maintenance > Analyze Database Structure.
Flush all cache - because TCA are in cache.
And your new field will now be available.

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

TCA Icon overlay in typo3 backend

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

How to use TYPO3 Link wizard in extension

In an extension, I would like to be able to modify an existing link. The corresponding field in the database is one which may contain several links (e.g. tt_content.bodytext).
I want to reuse as much already existing functionality as possible. So I would like to use the already existing link wizard.
What I did find was the existing route rteckeditor_wizard_browse_links which uses rte_ckeditor/Classes/Controller/BrowseLinksController.php.
I use this in my view helper:
$parameters = [
'table' => $table,
'fieldName' => $field,
'pid' => $pid,
'uid' => $uid,
'recordType' => $recordType;
];
$urlParameters = [
'contentsLanguage' => 'en',
// 'route'
// 'token*
'P' => $parameters,
'curUrl' => [
'url' => $url
// todo: add anchor text etc. ...
],
'editorId' => 'cke_1'
];
$route = 'rteckeditor_wizard_browse_links';
return (string)$uriBuilder->buildUriFromRoute($route, $urlParameters);
This does opens the link wizard correctly. But it is intertwined with the ckeditor.
When I press "Set link" nothing happens and I get the following JavaScript error (visible if Console is open in Browser):
RteLinkBrowser.js?bust=8d6016d70f0f490d5e7d24262f0ec96230f399d9:77 Uncaught TypeError: Cannot read property 'document' of null
at Object.LinkBrowser.finalizeFunction (RteLinkBrowser.js?bust=8d6016d70f0f490d5e7d24262f0ec96230f399d9:77)
at HTMLFormElement.UrlLinkHandler.link (UrlLinkHandler.js?bust=8d6016d70f0f490d5e7d24262f0ec96230f399d9:40)
at HTMLFormElement.dispatch (jquery.min-16985e7a97b69d2a9c29e484ac3b581a.js:2)
at HTMLFormElement.y.handle (jquery.min-16985e7a97b69d2a9c29e484ac3b581a.js:2)
LinkBrowser.finalizeFunction # RteLinkBrowser.js?bust=8d6016d70f0f490d5e7d24262f0ec96230f399d9:77
UrlLinkHandler.link # UrlLinkHandler.js?bust=8d6016d70f0f490d5e7d24262f0ec96230f399d9:40
dispatch # jquery.min-16985e7a97b69d2a9c29e484ac3b581a.js:2
y.handle # jquery.min-16985e7a97b69d2a9c29e484ac3b581a.js:2
The corresponding line in RteLinkBrowser.js is:
var linkElement = RteLinkBrowser.CKEditor.document.createElement('a');
The Link Wizard expects the ckeditor window to be open and uses things in the DOM that are not there.
Is there some way to directly open the link wizard for a specific link within a text field?
Or alternatively open the text field with ckeditor and have the specific link preselected.
I don't have an answer, but at least here is a work-around / alternative:
Don't open Link wizard directly, open field in editor
As an alternative, consider not using the link wizard but using the route 'record_edit' to open the edit dialog for a specific RTE field. If you double-click on a link in that, the link wizard will open.
The following example was taken from linkvalidator in the core and modified. It opens an editor dialog for the field tt_content.bodytext for the record with uid $uid.
$requestUri = GeneralUtility::getIndpEnv('REQUEST_URI') .
'&id=' . $pageid;
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
$url = (string)$uriBuilder->buildUriFromRoute('record_edit', [
'edit' => [
'tt_content' => [
$uid => 'edit'
]
],
'columnsOnly' => 'bodytext',
'returnUrl' => $requestUri
]);
Update: For TYPO3 9, a ViewHelper exists for opening the field with FormEngine in the Backend. This has the same result.
https://docs.typo3.org/other/typo3/view-helper-reference/9.5/en-us/typo3/backend/latest/Link/EditRecord.html

Drupal 8 - Entity Reference - Autocomplete - Add fields to search and result in autocomplete

I have an entity called "lawyers."
And another entity refers to lawyers.
The problem is that when searching the reference field with the autocompletion system many repeated names appear:
Pablo
Pablo
Pablo
Pablo
I need the reference field to be able to show the surnames of that person so that it turns out to be
Pablo Martínez
Paglo Gutirerrez
Pablo Iglesias
Pablo López
how can I do this?
You will have to create a Entity Reference View to use as handler for doing the autocomplete lookup. Then you can add additional fields (such as last name) to the autocomplete results. This article outlines that process well enough:
https://www.cmsminds.com/blog/entity-reference-entity-reference-view-in-drupal-8/
If the field is a base field and is not available on the Manage form Display page, you will have to modify the entity class Lawyer::baseFieldDefinitions function. Specifically, you need to change the handler and set the form display settings. In your BaseFieldDefinition::create call:
->setSetting('handler', 'default')
Needs to change to this:
->setSetting('handler', 'views')
->setSetting('handler_settings', [
'view' => [
'view_name' => 'name_of_entity_reference_view',
'display_name' => 'name_of_view_display',
],
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 2,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
Alternatively, if you want to make base fields available in the UI, you can use this line to make the field available in the form display settings ui (and then export your form display settings as config:
->setDisplayConfigurable('form', TRUE);