I'm trying to create a extension to modify fields in a different extension.
My extension needs to add and disable fields in fe_users over the TSConfig Page.
Ive looked over google how to do this with a own extension. But I didn't find anything usefull that I could work with.
(Edited)
The admin shouldn't be able to see these fields:
Company
Name
Middle name
Address
Zipcode
Land
Phone
Fax
www
Image
TSConfig
Bind a Domain
Redirect after login
Start
Stop
Record Type
These fields should be added
Customer (INT, not able to edit on display) Manditory
swissaxis_id (INT, Unique number) if possible only displayable and
not editing possibility
shop_rights (Textarea, No defined Value. The Rights will be saved
there serialised.)
fe_groups
These fields shouldn't be displayed to any Admin
Bind a domain
TSConfig
Redirect after login
Record Type
I'm thankfull for any Feedback possible.
Here's a link on how you add new fields to fe_users: https://docs.typo3.org/typo3cms/TCAReference/ExtendingTca/Index.html
https://docs.typo3.org/typo3cms/TCAReference/ExtendingTca/Examples/Index.html
I'll give you an example from an old, makeshift extension zusatzfelder of mine that modifies the "pages" table. It's really old, please verify if everything is current. You can also look at any other, "real" extension...
ext_emconf.php (maybe created by extension_builder)
<?php
########################################################################
# Extension Manager/Repository config file for ext "zusatzfelder".
#
# Auto generated 29-08-2011 15:33
#
# Manual updates:
# Only the data in the array - everything else is removed by next
# writing. "version" and "dependencies" must not be touched!
########################################################################
$EM_CONF[$_EXTKEY] = array(
'title' => 'Zusatzfelder',
'description' => '',
'category' => '',
'author' => '',
'author_email' => '',
'shy' => '',
'dependencies' => '',
'conflicts' => '',
'priority' => '',
'module' => '',
'state' => '',
'internal' => '',
'uploadfolder' => 0,
'createDirs' => '',
'modify_tables' => '',
'clearCacheOnLoad' => 0,
'lockType' => '',
'author_company' => '',
'version' => '0.0.0',
'constraints' => array(
'depends' => array(
),
'conflicts' => array(
),
'suggests' => array(
),
),
'_md5_values_when_last_written' => 'a:8:{s:9:"ChangeLog";s:4:"5b94";s:10:"README.txt";s:4:"ee2d";s:12:"ext_icon.gif";s:4:"1bdc";s:14:"ext_tables.php";s:4:"474a";s:14:"ext_tables.sql";s:4:"ead9";s:16:"locallang_db.xml";s:4:"7a92";s:19:"doc/wizard_form.dat";s:4:"0cba";s:20:"doc/wizard_form.html";s:4:"29e8";}',
);
?>
ext_tables.sql
CREATE TABLE pages (
tx_zusatzfelder_contentnav_title_addition tinytext,
tx_zusatzfelder_contentnav_title tinytext,
tx_zusatzfelder_contentnav_disable int(11) DEFAULT '0' NOT NULL,
);
ext_tables.php
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
$tempColumns = array (
'tx_zusatzfelder_contentnav_title' => array (
'exclude' => 0,
'label' => 'LLL:EXT:zusatzfelder/locallang_db.xml:pages.tx_zusatzfelder_contentnav_title',
'config' => array (
'type' => 'input',
'size' => '30',
)
),
'tx_zusatzfelder_contentnav_title_addition' => array (
'exclude' => 0,
'label' => 'LLL:EXT:zusatzfelder/locallang_db.xml:pages.tx_zusatzfelder_contentnav_title_addition',
'config' => array (
'type' => 'input',
'size' => '30',
)
),
'tx_zusatzfelder_contentnav_disable' => array (
'exclude' => 0,
'label' => 'LLL:EXT:zusatzfelder/locallang_db.xml:pages.tx_zusatzfelder_contentnav_disable',
'config' => array (
'type' => 'check',
'default' => '0',
)
),
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages',$tempColumns,1);
// http://typo3-blog.net/tutorials/news/addtoalltcatypes.html
// PS: the "after:"... is for placement in the BE, stopped working last week...
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('pages','tx_zusatzfelder_contentnav_title;;;;1-1-1','','after:subtitle');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('pages','tx_zusatzfelder_contentnav_title_addition;;;;1-1-1','','after:subtitle');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('pages','tx_zusatzfelder_contentnav_disable;;;;1-1-1','','after:subtitle');
?>
locallang_db.xml
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<T3locallang>
<meta type="array">
<type>database</type>
<description>Language labels for database tables/fields belonging to extension 'zusatzfelder'</description>
</meta>
<data type="array">
<languageKey index="default" type="array">
<label index="pages.tx_zusatzfelder_contentnav_title_addition">Untermenu: Vorlauf Titel (zB. "Mehr zur")</label>
<label index="pages.tx_zusatzfelder_contentnav_title">Untermenu: Titellink anderer Text (Standard: Seitentitel; Leerschlag: kein Titel)</label>
<label index="pages.tx_zusatzfelder_contentnav_disable">Untermenu ausblenden</label>
</languageKey>
</data>
</T3locallang>
That's all you need to add new fields – you don't even need the locallang if you just prefer to do 'label' => 'My untranslated Label', in ext_tables.php.
Related
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
I am currently adding a web hook and want to add some fields programmatically through the manifest.php.
I have found the relevent information to add fields as below:
'custom_fields' => array (
array (
'name' => 'text_c',
'label' => 'LBL_TEXT_C',
'type' => 'varchar',
'max_size' => 255,
'require_option' => 'optional',
'default_value' => '',
'ext1' => '',
'ext2' => '',
'ext3' => '',
'audited' => 1,
'module' => 'Accounts'
)
);
the issue is that I cant seem to find how to make the fields dependant i.e. they will only be visible if another field contains a specific value.
any help would be greatly appreciated
In the definition array you would need to add the dependency attribute like so :
'custom_fields' => array (
array (
'name' => 'text_c',
'label' => 'LBL_TEXT_C',
'type' => 'varchar',
'max_size' => 255,
'require_option' => 'optional',
'default_value' => '',
'ext1' => '',
'ext2' => '',
'ext3' => '',
'audited' => 1,
'module' => 'Accounts'
'dependency' => 'equal($other_field,"other field value")'
)
);
This would replicate setting the dependency option in Studio.
The dependency formula
'equal($other_field,"other field value")'
Means show this field when the another field other_field equals the string "other field value"
I want to add a field in the backend of the new news module. For that I created a new extension with 3 files in it:
ext_emconf.php
<?php
$EM_CONF[$_EXTKEY] = array(
'title' => 'Expand news',
'description' => 'Expand news',
'category' => 'fe',
'author' => 'SOG',
'author_email' => '-',
'shy' => '',
'dependencies' => '',
'conflicts' => '',
'priority' => '',
'module' => '',
'state' => 'stable',
'internal' => '',
'uploadfolder' => 0,
'createDirs' => '',
'modify_tables' => '',
'clearCacheOnLoad' => 0,
'lockType' => '',
'author_company' => '',
'version' => '0.1.0',
'constraints' => array(
'depends' => array(
),
'conflicts' => array(
),
'suggests' => array(
),
),
'_md5_values_when_last_written' => '',
'suggests' => array(
),
);
?>
ext_tables.php
<?php
/*if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}*/
$tempColumns = array(
'tx_sogexpandnews_test' => array(
'exclude' => 0,
'label' => 'test',
'config' => array(
'type' => 'text',
'cols' => '30',
'rows' => '5',
)
),
);
t3lib_div::loadTCA('tx_news_domain_model_news');
t3lib_extMgm::addTCAcolumns('tx_news_domain_model_news',$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes('tx_news_domain_model_news','tx_sogexpandnews_test', '', 'after:title'));
?>
ext_tables.sql
#
# Table structure for table 'news'
#
CREATE TABLE tx_news_domain_model_news (
tx_sogexpandnews_test text
);
The field is in the database but I dont see the field in the backend when I wanna create a new news item.
I also checked LocalConfiguation.php and made sure that my extension is under the news extension.
Any idea what I miss?
I can't tell why but I deactived news, updated it and installed it again and now I see the field.
cache - cache - cache ... always cache.
If you need to be sure, always delete everything in typo3temp and flush all cf_* tables in your db.
(deactivating and reinstalling almost does the same)
I "kickstarted" an extension with the extbase extension builder that contains some 1:1 and 1:n relations. It automatically set the field types to 'inline' and displayed a nice IRRE UI in the backend.
But by default, there is no way to select an existing record, just create new ones.
I found various explanations on how to achieve this with 'foreign_selector', but all of them very sketchy. The feature itself should be working, see https://forge.typo3.org/issues/43239
Can someone walk me through this or point to a working example in the TER? I could create a step-by-step tutorial from the example, once I get it to work.
PS The field's TCA config as generated by extension_builder:
'myfield' => array(
'exclude' => 1,
'label' => 'LLL:EXT:myextension/Resources/Private/Language/locallang_db.xlf:tx_myextension_domain_model_myitem.myfield',
'config' => array(
'type' => 'inline',
'foreign_table' => 'tx_myextension_domain_model_myfield',
'foreign_field' => 'myitem',
'maxitems' => 9999,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
),
),
),
The main problem is that IRRE relations of type 1:n work like this: A child record holds the uid of its parent. So your table tx_myext_domain_model_city holds the UID of your (imaginary) tx_myext_domain_model_address.
Therefore with the default configuration you will not be able to select a city multiple times as it can only have exactly one parent.
So you will need to use a relation table for this field. This table needs to contain a uid field for both the address (uid_address) and the city (uid_city):
CREATE TABLE tx_irreforeignselectordemo_address_city_mm (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
uid_address int(11) unsigned DEFAULT '0' NOT NULL,
uid_city int(11) unsigned DEFAULT '0' NOT NULL,
sorting int(11) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid)
);
And it needs to have a TCA configuration for these fields (while the table itself can be hidden):
return array(
'ctrl' => array(
'title' => 'Relation table',
'hideTable' => TRUE,
'sortby' => 'sorting',
),
'columns' => array(
'uid_address' => Array(
'label' => 'Address',
'config' => Array(
'type' => 'select',
'foreign_table' => 'tx_irreforeignselectordemo_domain_model_address',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
'uid_city' => Array(
'label' => 'City',
'config' => Array(
'type' => 'select',
'foreign_table' => 'tx_irreforeignselectordemo_domain_model_city',
'foreign_table_where' => ' AND sys_language_uid IN (0,-1)',
'size' => 1,
'minitems' => 0,
'maxitems' => 1,
),
),
),
'types' => array(
'0' => array('showitem' => 'uid_address,uid_city')
),
'palettes' => array()
);
You can then configure the TCA of your address to make it an IRRE field:
'type' => 'inline',
'foreign_table' => 'tx_yourext_address_city_mm',
'foreign_field' => 'uid_address',
'foreign_label' => 'uid_city',
'foreign_selector' => 'uid_city',
'foreign_unique' => 'uid_city',
'foreign_sortby' => 'sorting',
Note that foreign_unique tells TYPO3 that a city can only selected once.
And you need to define the relation from the other side (from your city TCA):
'addresses' => array(
'exclude' => 1,
'label' => 'Addresses',
'config' => array(
'type' => 'inline',
'foreign_table' => 'tx_irreforeignselectordemo_address_city_mm',
'foreign_field' => 'uid_city',
'foreign_label' => 'uid_address',
),
),
Once your configuration is complete, you will be able to use this in the Backend.
Since this is a non-standard MM relation, Extbase will not be able to deal with it by default. But we can compare this to the sys_file_reference table that was introduced in TYPO3 6. So we build an Extbase model for the CityRelation with the properties "address" and "city" and map this model to our mm table:
config.tx_extbase.persistence.classes {
Visol\Irreforeignselectordemo\Domain\Model\CityRelation {
mapping {
tableName = tx_irreforeignselectordemo_address_city_mm
columns {
uid_address.mapOnProperty = address
uid_city.mapOnProperty = city
}
}
}
}
Now in our address model, we define the city (or cities - of you allow more than one choice) as ObjectStorage of type CityRelation:
/**
* Cities
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Visol\Irreforeignselectordemo\Domain\Model\CityRelation>
*/
protected $cities = NULL;
We now have a property "cities" that contains the references to all selected cities. You can iterate through them and use them:
<f:for each="{address.cities}" as="cityRelation">
<li>{cityRelation.city.name}</li>
</f:for>
Since I couldn't find an all-in-one demo for this and was interested in the topic, I created a demo extension that does what I just described - based on the Core and two extensions that deal with the topic: https://github.com/lorenzulrich/irreforeignselectordemo
The solution is an m:n approach anyway (because 1:n wouldn't work for the reasons stated above) so I decided to use "cities" instead of "city". While this might not make sense for selecting a city (as suggested by your post), it might make sense for other opportunities. Feel free to replace "cities" by "city" and set maxItems in the inline configuration to one - then you have kind of an 1:n.
I have a field defined as such:
max_items int(11) NULL
If you leave this field empty in the backend I want it to store NULL.
For this I use this configuration in the TCA, which doesn't work:
'max_items' => array(
'exclude' => 0,
'label' => '...',
'config' => array(
'type' => 'input',
'eval' => 'null',
),
),
Edit:
Instead of storing the expected value NULL, it stores 0.
I tried max_items int(11) DEFAULT NULL, but that didn't work aswell.
Edit2:
Thanks freshp!
I ended up writing my own eval function:
<?php
class tx_myextension_evalfunc {
function evaluateFieldValue($sValue, $aIsIn, &$bSet)
{
return ($sValue === '') ? null : $sValue;
}
}
?>
Using this configuration:
'max_items' => array(
'exclude' => 0,
'label' => '...',
'config' => array(
'type' => 'input',
'eval' => 'tx_myextension_evalfunc',
),
),
There was a bug in older TYPO3 versions:
The current implementation in the TYPO3 backend does not allow to store NULL values, only empty strings or zero as number are allowed.
This bug is fixed in TYPO3 6.0 and higher. In the TCA config there is a new eval option "null":
'config' = array(
'type' => 'input',
'eval' => 'null',
...
);
If this option is enabled, there is a checkbox at the right side of the input. If it's deactivated, the NULL value is saved to the database, if it is activated, an integer value can be entered.
If you want to have the checkbox per default deactivated to store Null as default, add 'default' => null to it:
'config' = array(
'type' => 'input',
'eval' => 'null',
'default' => null,
);
Tested in TYPO3 8 LTS. Then it looks like this:
Original answer:
There are two interesting links for you:
the core-bug for your question - http://forge.typo3.org/issues/41773
one way to fix it with a own eval-function - http://www.blogix.net/2008/05/10/eigene-eval-funktion-in-typo3-tca/