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.
Related
I am using TYPO3 9.5.26 with tx_news 8.5.2. I have extended sys_file_reference with my own field. I can access this fields value in my fluid templates like so:
{file.properties.tx_myext_frame}
This is tested and works fine. However in the news module this stays empty
{mediaElement.properties.tx_myext_frame}
How can I use the orginalFile properties in tx_news?
Thanks
Code I use to add the field:
typo3conf\ext\myext\ext_tables.sql
CREATE TABLE sys_file_reference (
tx_myext_frame tinyint(4) DEFAULT '0' NOT NULL,
);
typo3conf\ext\myext\Configuration\TCA\Overrides\sys_file_reference.php
// Add some fields to sys_file_reference table
$temporaryColumns = [
'tx_myext_frame' => [
'exclude' => 0,
'label' => 'LLL:EXT:myext/Resources/Private/Language/locallang_db.xlf:tx_myext_frame',
'config' => [
'type' => 'check',
'default' => '0',
]
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
'sys_file_reference',
'imageoverlayPalette',
'--linebreak--,tx_myext_invert,tx_myext_frame',
'after:description'
);
found the answer myself just now - so for anyone trying this use
{mediaElement.originalResource.properties.tx_myext_frame}
The title is rather self explanatory, but what i would like to have is a dynamic default value.
The idea behind it is to get the biggest number from a column in the database and then add one to the result. This result should be saved as the default value.
Lets take for example this code:
$GLOBALS['TCA'][$modelName]['columns']['autojobnumber'] = array(
'exclude' => true,
'label' => 'LLL:EXT:path/To/The/LLL:tx_extension_domain_model_job_autojobnumber',
'config' => [
'type' => 'input',
'size' => 10,
'eval' => 'trim,int',
'readOnly' =>1,
'default' => $result,
]
);
The SQL looks like this:
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_extension_domain_model_job');
$getBiggestNumber = $queryBuilder
->select('autojobnumber')
->from('tx_extension_domain_model_job')
->groupBy('autojobnumber')
->orderBy('autojobnumber', 'DESC')
->setMaxResults(1)
->execute()
->fetchColumn(0);
$result = $getBiggestNumber + 1;
So how can i do that "clean"?
I thought about processCmdmap_preProcess but i dont know how to pass the value to the coorisponding TCA field. Plus i do not get any results on my backend when i use the DebuggerUtility like i get them when i use processDatamap_afterAllOperations after saving the Object.
Can someone point me to the right direction?
I don't think it is supported to create a dynamic default value, see default property of input field.
What you can do however, is to create your own type (use this instead of type="input"). You can use the "user" type. (It might also be possible to create your own renderType for type="input", I never did this, but created custom renderTypes for type= "select").
You can look at the code of InputTextElement, extend that or create your own from scratch.
core code: InputTextElement
documentation for user type
more examples in FormEngine documentation
Example
(slightly modified, from documentation)
ext_localconf.php:
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][<current timestamp>] = [
'nodeName' => 'customInputField',
'priority' => 40,
'class' => \T3docs\Examples\Form\Element\CustomInputElement::class,
];
CustomInputElement
<?php
declare(strict_types = 1);
namespace Myvendor\MyExtension\Backend\FormEngine\Element\CustomInputElement;
use TYPO3\CMS\Backend\Form\Element\AbstractFormElement;
// extend from AbstractFormElement
// alternatively, extend from existing Type and extend it.
class CustomInputElement extends AbstractFormElement
{
public function render():array
{
$resultArray = $this->initializeResultArray();
// add some HTML
$resultArray['html'] = 'something ...';
// ... see docs + core for more info what you can set here!
return $resultArray;
}
}
How can we add new fields in a new tab in user setting in TYPO3 version 8.7?
Our problem is the creation of a new tab.
I can add new fields to personal data tab in user setting, but I need to create new fields into a new tab.
For backend admin user setting I added a new tab, but for user setting I want to try this. I have an extension and since the installation of the extension it will add-on.
I tried to create new tab in fe_user.php.
Previously I tried to change ext_tables.php, but that is not working at all.
// Add some fields to FE Users table to show TCA fields definitions
// USAGE: TCA Reference > $GLOBALS['TCA'] array reference >
// ['columns'][fieldname]['config'] / TYPE: "select"
$temporaryColumns = array (
'tx_examples_options' => array (
'exclude' => 1,
'label' => 'tx_examples_options',
'config' => array (
'type' => 'select',
'showitem' => array (
array('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:fe_users.tx_examples_options.I.0', '1'),
array('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:fe_users.tx_examples_options.I.1', '2'),
array('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:fe_users.tx_examples_options.I.2', '--div--'),
array('LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:fe_users.tx_examples_options.I.3', '3'),
),
'size' => 1,
'maxitems' => 1,
)
),
'tx_examples_special' => array (
'exclude' => 1,
'label' => 'tx_examples_special',
'config' => array (
'type' => 'user',
'size' => '30',
'userFunc' => 'Documentation\\Examples\\Userfuncs\\Tca->specialField',
'parameters' => array(
'color' => 'blue'
)
)
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'fe_users',
$temporaryColumns
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'fe_users',
'--div--;newtab,tx_examples_options, tx_examples_special'
);
When I changed into file ext_tables.php
$GLOBALS['TYPO3_USER_SETTINGS']['columns']['copy_directory'] = array(
'label' => 'Alternative directory for saving copies',
'type' => 'text',
'table' => 'be_users',
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToUserSettings('copy_directory','after:lang');
then it's showing in "personal data" tab but I want new tab in user setting for non-admin user.
In general your code looks fine.
But you are in the wrong file!
Avoid ext_tables.php if possible.
If you change anything to the TCA you should do it in Configuration/TCA/ for new tables and Configuration/TCA/Overrides for enhancing existing tables.
Use filenames according to the table you are modifying.
In your case all the code should be located in Configuration/TCA/Overrides/fe_users.php.
And be sure you clear all caches if you develop anything with TCA!
I've built a extension where I can assign content elements (tt_content) inline (IRRE) to my entries in the TYPO3 Backend.
But I can't figure out how I can resolve the relations so that I can display the assigned content elements in the frontend.
I've created the extension with the 'Extension Builder' in TYPO3 9.5.5.
I created a Model Object 'Content' and selected 'Map to existing table' in the 'Domain object settings' and choosed 'tt_content'.
In my model 'ProductTab' I configured a 1:n relation of type 'Inline (IRRE)' with the name 'content' to my 'Content' model.
If I add content elements to my model entries in the Backend, it works like expected. The relational fields in the DB are mapped correctly. With the 'Extbase Variable Dump' I can see that all my relations are passed to the front end plugin, but my 'content' relation is an empty 'ObjectStorage'.
What am I missing so that the extbase persistence fetches my content relations?
ext_tables.sql excerpts
CREATE TABLE tx_myext_domain_model_producttab (
product int(11) unsigned DEFAULT '0' NOT NULL,
title varchar(255) DEFAULT '' NOT NULL,
content int(11) unsigned DEFAULT '0' NOT NULL,
);
CREATE TABLE tt_content (
producttab int(11) unsigned DEFAULT '0' NOT NULL,
);
TCA excerpts
'content' => [
'exclude' => false,
'label' => 'producttab.content',
'config' => [
'type' => 'inline',
'foreign_table' => 'tt_content',
'foreign_field' => 'producttab',
'maxitems' => 9999,
'appearance' => [
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
],
],
],
Since I can add and edit the content elements in the Backend, I think the DB and TCA relation is fine.
But something is still missing, so that the relation is fetched and provided to the FE template so that I can display the assigned content elements with a ViewHelper.
ProductTab.php excerpts
class ProductTab extends \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject
{
protected $content = null;
protected function initStorageObjects()
{
$this->content = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
public function addContent(\MyExt\Domain\Model\Content $content)
{
$this->content->attach($content);
}
public function removeContent(\MyExt\Domain\Model\Content $contentToRemove)
{
$this->content->detach($contentToRemove);
}
public function getContent()
{
return $this->content;
}
public function setContent(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $content)
{
$this->content = $content;
}
}
Extbase Variable Dump
Screenshot of debug output
On the screenshot you can see the fetched products (one item in this case) and the producttabs (also 1 item). There is one content element assigned, but the property content of the ProductTab with uid=1 is empty.
Update
Since I'm still not able to solve this issue, I've created a minimalistic extension with the Extension Builder to demonstrate the issue: https://github.com/apiening/demo_irrecontent
The extension is the most simple one I could create with one model holding only one property and the relation to tt_content. It has a plugin list which also shows the debug output.
I've put some more details in the README.mdof the GitHub project.
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