TYPO3 TCA field should have default value after copy - typo3

When I copy a record (e.g. a page), I would like the content of a field to (always) have the default value, not the value of the original record. But for my custom field, it always has the value of the original record and I can't find configuration to change this (e.g. in the TCA documentation).
(This is not about how the field should be handled when translating, this is just about copying in the default language).
The field TCA is (simplified):
'my_field' => [
'label' => 'Subnavigation',
'l10n_mode' => 'exclude',
'config' => [
'type' => 'check',
'default' => 0,
'items' => [
[
'check box 1',
''
],
[
'checkbox 2',
''
],
],
],
],
my_field has the value 3, currently in the original record. The copied record should have the value 0.

There are several settings to influence the values of copies, the closest one seems to be useColumnsForDefaultValues, I doubt though that it's exactly what you need.
Further options are copyAfterDuplFields, prependAtCopy and hideAtCopy.
On the first linked page is also mentioned that default values in TSconfig can be set, those are only working when a record is opened and empty, so that is likely not solving the problem.
It might also be possible that you had columnsOverrides in mind, I neither see though that this option meets the requirement.
I suppose you need to program a function for it, i.e. on base of the ModifyRecordListRecordActionsEvent.
Another option concerning programming would be using a hook perhaps.

Related

TYPO3 EXT:cart_product: extend backend with one selection to do conditional theming in template

I'm looking for a way to extend the backend of the TYPO3 extension cart_products with one additional select field. I have already created some different ViewHelpers for the ProductBackendVariants and now need a way to choose the corresponding Viewhelper.
Best would be if there is a selection direct after the type select in the general product type. But I am not able to add some additional configuration fields to this tab.
Already added
'formtemplate' => [
'label' => 'ProductDetail Variant Form',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['Standard', 1],
['Matten', 2],
['Zaunpaket', 3],
],
'size' => 1,
'minitems' => 1,
'maxitems' => 1,
],
],
to the tx_cartproducts_domain_model_product_product.php but nothing appears in the backend.
I don't know that specific extension but some hints in general:
it seems that you have tried to modified the TCA directly in the extension (cart_products/Configuration/TCA/tx_cartproducts_domain_model_product_product.php). You should never change anything in a 3rd party extension (neither the TYPO3 core) because you loose the ability to update.
You need to create your own extension and add a file to Configuration/TCA/Overrides. Ideally you name the file exactly like the file you like to extend for easier understanding. See the documentation for details.
To add a new field to the TCA you not only need to define the name and type but you also need to create the database field. That's done in ext_tables.sql of your custom extension.
It's not sufficent to create the TCA config and SQL mentioned above you also need to tell, where the new field should be visible in the backend. That's done with the showitem setting. See documentation for details.
To ease the process of extending an existing TCA I can recommend the extension TCA Builder which makes it in many cases much easier to create the TCA code. See these examples how that's done. Nevertheless you need to create ext_tables.sql.
Last but not least: when you made changes to ext_tables.sql you need to run the database compare in the TYPO3 install tool.

FormType ChoiceType (select) data preset not working in view Symfony 3.4

In a Symfony 3.4 Application I have defined a MyFormType class with a ChoiceType element like that
$builder->add(
'my_field_1',
ChoiceType::class,
array(
'label' => 'My Label',
'placeholder' => 'nothing selected',
'choices' => $choicesArray,
'multiple' => false,
'expanded' => false,
'required' => false,
'mapped' => true,
'data' => $choicesPreset,
)
);
In a Controller I create the form passing in the needed object to preset data and then I pass the created view to a twig template.
In the template the form is rendered OK. Everything works except that the preset value of the ChoiceType select element is not set. The field is rendered with the placeholder option selected.
All other elements of the same form do load their preset values without problems. None of them is a ChoiceType though.
When debugging I see that the preset value is correct when creating the form class and also it is set to the field (I am not sure though which properties exactly have to be set in the FormBuilder element).
While debugging the ChoiceType preset value looks OK in the Controller as well.
However the template renders the placeholder.
I am not sure how to debug twig templates and if I knew I wouldn't know what to look for.
Any hints on what could go wrong here are very welcome.
EDIT:
While checking the choices and preset values aI discovered that the problem is actualy not coming from the form field itself or any of its options but from a data transformer.
I have this line directly below the code postet above:
$builder->get('my_entity')->addModelTransformer( $this->myEntityToNumberTransformer );
When deleting this line the preset value works (not the transformer though. Obviously...). So the question is acutaly: Why does the data transformer interfere with the preset value setup?
The problem was not in the field or the preset values but in the data transformer I mentioned in my edit. Fixing the data transformer fixed the problem with no preset values as well.

Typo3 override backend classes

It's been a few weeks I work on Typo3 6.2 and I want to know how to override Typo3 Core classes.
In my case, I have to edit the way select html objects are displayed (I want to add optgroup but Typo doesn't allow us to do it). So I edited the file "FormEngine.php" (typo3/sysext/backend/Classes/Form) and now it works.
But this isn't healthy for future upgrade.
Is there a way to override core classes like any other CMS would allow us to do ?
And I haven't been able to find something on the Internet and I think it could be useful.
Thank you :)
Zisiztypo
Instead of modifying source code of CMS you can just declare a field with a user type and then point your custom userFunc
From the ref:
'tx_examples_special' => array (
'exclude' => 0,
'label' => 'LLL:EXT:examples/Resources/Private/Language/locallang_db.xlf:fe_users.tx_examples_special',
'config' => array (
'type' => 'user',
'size' => '30',
'userFunc' => 'Documentation\\Examples\\Userfuncs\\Tca->specialField',
'parameters' => array(
'color' => 'blue'
)
)
),
TIP: Using this approach, you can create ANY type of field you need, it can be i.e. Google Maps selector, set of fields with common dependencies filled by JS, etc, etc.

TYPO3 modify backend table

EDIT: TYPO3 version 4.7
there is table Create Website user with many tabs.
I am able to add new tab with my own data using:
$test = array(
'tx_promconf_send_email' => array(
'exclude' => 0,
'label' => 'HAHAHA',
'config' => array(
'type' => 'input'
,)));
t3lib_div::loadTCA('fe_users');
t3lib_extMgm::addTCAcolumns('fe_users',$test,1);
t3lib_extMgm::addToAllTCAtypes('fe_users','--div--;Documents;;;;1-1-1,tx_promconf_send_email');
But I am not able to put my input to already existing tabs. Also I was not able to find some explanation of this string 'fe_users','--div--;Documents;;;;1-1-1,tx_promconf_send_email'.
Is there an option how to modify existing tabs? Where can I found the name of the tab? I tried to use instead of --div-- name of the tab and it does not work.
This weird string is hardly documented. You can find the TCA Documentation here.
If you want to insert it to an existing tab, just do it by finding a field within the desired tab where you want to put your new field after or before.
For example:
t3lib_extMgm::addToAllTCAtypes('fe_users','tx_promconf_send_email', '', 'after:last_name');
Your field will now be displayed after the field "last_name", and so within the tab "Personal Data". You can also use "before:fieldname" to insert your field before a field.

Add a dropdown list as custom field in magento

I added custom fields as described in magento add custom input field to customer account form in admin
But I want a select list, not only a text input one. I don't know which kind of parameter I have to set and how to tell the list of possible values.
Please help :)
Thanks,
Plantex
Where you might do something like:
$setup->addAttribute('customer', 'custom_attribute', array(
'type' => 'text',
'label' => 'Customer Custom Attribute',
));
Use these values instead:
$setup->addAttribute('customer', 'custom_attribute', array(
'type' => 'int',
'label' => 'Customer Custom Attribute',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
));
The type is int because you will typically be storing the index of the value chosen, not the value itself. The input is select so the admin renderer knows which control to use. The source shown here is a common example, it provides an array of "Yes" and "No" values with numeric indexes.
There are many source models already in the Magento code that you can use and you can create your own too, look at any existing one to see how it returns an array. If you make your own and if it uses text indexes instead of numeric then the type will have to be changed back to text.
Try adding this at your module setup file
'value' => array('notate_to_zero'=>array(0=>'Bleu',0=>'Rouge',0=>'Vert',0=>'Violet',0=>'Noir',0=>'Orange'))
),
or look at this --> http://inchoo.net/ecommerce/magento/how-to-create-custom-attribute-source-type/