TYPO3: How to set up textfield in custom content element to avoid missing file references in backend filelist? - typo3

How to set up textfield in custom content element to avoid missing file references in backend filelist
I have a custom content element with a field of type "text". When I link in this field to a file in fileadmin there is no reference counted in the backend.
How I have to configure the field in my TCA to regard the references from that field in the file list?
My TCA-Config for that field is:
'my_ext_fiedname' =>
array(
'config' =>
array(
'type' => 'text',
'eval' => 'required',
'richtextConfiguration' => 'default',
'enableRichtext' => '1',
),
'exclude' => '1',
'label' => 'title',
),

Try to avoid using media references in text fields. It has been difficult over the past years to upgrade TYPO3 with such configuration and usages.
If you can't avoid, try using extension rte_ckeditor_image from Christian Opitz which is regularly maintained.

Related

How to get 'friendly' text of a TYPO3 MultiSelect field in the TYPO3 Fluid template?

I have a multi select field that is defined by TCA that way:
'type' => [
'exclude' => true,
'label' => 'LLL:EXT:extension/Resources/Private/Language/locallang_db.xlf:tx_extension.type',
'config' => [
'type' => 'select',
'renderType' => 'selectCheckBox',
'items' => [
['LLL:EXT:extension/Resources/Private/Language/locallang_db.xlf:tx_extension.type.b', 'b'],
['LLL:EXT:extension/Resources/Private/Language/locallang_db.xlf:tx_extension.type.w', 'w'],
],
'size' => 1,
'maxitems' => 2,
'eval' => 'required'
],
],
In the backend form everything works as expected, but when selecting the data in a frontend controller from the database, for example by ->findAll(), I only get 'b', 'w' or 'b,w' as values.
Is there a simple way to get the 'friendly' names?
When using relations to other tables, the values are getting resolved, but not when using static items as values for the select.
I was thinking about using the translate view helper <f:translate key="{value}" extensionName="extension" /> but this will fail when more than one item is selected.
Then I was trying to write an own view helper but failed with the initialisation of the translation factory service (that does not exist in TYPO3 v8.7!!!). Then calling the TranslateViewHelper::renderStatic() method failed because I did not find a way to get the RenderingContextInterface what is needed as third parameter.
Anyway, isn't there a smarter way to solve my problem (in good old TYPO3 v9 ☹️)?

How can I sort a views field created in hook_views_data_alter?

In a custom drupal 9 module I define a new field for a view within hook_views_data_alter(&$data).
$data['node']['node_views_mydata'] = array(
'title' => t('Node Views Mydata'),
'field' => array(
'title' => t('Node views mydata'),
'help' => t('Shows some data in views'),
'id' => 'node_views_mydata',
'sort' => [
'node_views_mydata' => 'default',
],
)
);
I have also defined a field plugin processing text data for this field, and can insert and output the field in views.
Now I would like to make the field sortable. But I can't do that. I always get the error "unknown column". In fact, node_views_data is not a "real" node field, but only created on the fly via the hook.
Is there nevertheless a way to sort by this column?

TYPO3 TCA and select form

I try to get values for my tca:
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['Herr', 0],
['Frau', 1]
],
'size' => 1,
'maxitems' => 2,
'eval' => 'required'
],
my form.html has this select types:
<label>Anrede</label>
<f:form.select name="salutation" class="form-control">
<f:form.select.option value="0">Herr</f:form.select.option>
<f:form.select.option value="1">Frau</f:form.select.option>
</f:form.select>
but i get always the first item: Herr, can somebody tell me what i am doing wrong?
For frontend forms with Extbase you will need a proper TypoScript conffiguration, a PHP newAction and/or createAction method and your Fluid template.
Based on the additional information now there are two options that came to my mind:
Either the validation and storage of your form values is not
configured properly, so they will be removed on the way to the
database.
Or you might have rendered the field twice with the same name in the
frontend form, thus making the last entry the winner.
So please double check the fields first before digging deeper into the storage process.
https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/7-Controllers/1-Creating-Controllers-and-Actions.html

How to add custom wizards in typo3 7 TCA?

When I try to add the wizard named wizard_geo_selector in TCA ,there arised an error "module not registered".Please tell me how to register the wizard properly in the TCA.?
In TYPO3 Version 7.6 new wizards are added like this:
Inside your extension create the directory Configuration/Backend/
In the new directory create a file Routes.php, it will be found automatically, no mentioning in ext_localconf.php or ext_tables.php is required. If you still need Ajax you can add the file AjaxRoutes.php in the same folder.
Content for Routes.php:
return array(
'my_wizard_element' => array(
'path' => '/wizard/tx_geoselecotor/geo_selector_wizard',
'target' => \Path\To\your\class\WizardGeoSelector::class . '::WizardAction'
),
);
Content for AjaxRoutes.php
<?php
/**
* Definitions for routes provided by EXT:backend
* Contains all AJAX-based routes for entry points
*
* Currently the "access" property is only used so no token creation + validation is made
* but will be extended further.
*/
return array('my_ajax_element' => array(
'path' => 'tx_geoselecotor/my_ajax_route',
'target' => \Path\To\your\class\MyAjaxController::class .'::myAjaxFunction'
));
If you're unsure about the notation you can compare with existing entries in the Global Variables in the Backend:
Navigate to System -> Configuration -> Backend Routes
The route of the paths is handled different, for Ajax it's always "ajax" prepended, so you've never to add it to the path, else it's twice in the route. For the common route there is no change concerning the defined string.
Now the wizard can be used and even it never has to be defined in ext_tables.php it has to be mentioned there from any table-field in the configuration-area (module[name]):
'table_field_for_wizard' => array(
'label' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xml:table_name.tx_myextension_wizard',
'config' => array (
'type' => 'user',
'userFunc' => 'Path/to/class/without/wizard->renderForm',
'wizards' => array(
'my_wizard' => array(
'type' => 'popup',
'title' => 'MyTitle',
'JSopenParams' => 'height=700,width=780,status=0,menubar=0,scrollbars=1',
'icon' => 'EXT:' . $_EXTKEY . '/Resources/Public/img/link_popup.gif',
'module' => array(
'name' => 'my_wizard_element',
'urlParameters' => array(
'mode' => 'wizard',
'ajax' => '0',
'any' => '... parameters you need'
),
),
),
'_VALIGN' => 'middle',
'_PADDING' => '4',
),
# Optional
#'softref'=>'something',
),
),
In the userFunc Path/to/class/without/wizard->renderForm you've to create a button which is linking to the wizard and onClick the wizard will open with the route you defined in Routes.php and the optional urlParameters.
Currently I never found this whole item explained in the core-documentation.
Edit:
Details about routing can be found here: Routing
The rendering process can be found here: Rendering / NodeFactory
You should probably read also the outer context of the linked paragraph.
Edit 2:
An example extension can be found here, some things never work 100% but the wizard is working. The extension is for TYPO3 Version 7:
https://github.com/DavidBruchmann/imagemap_wizard
Ricky's answer doesn't really work anymore, since addModulePath ist deprecated since version 7.
Also, just registering the module like this still give's you said error.
The only thing that keeps the wizard going again is this:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule('wizard','pbsurvey_answers',"",\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY).'wizard/');
But when you add this, the module appears as a new point in your TYPO3 backend.
IN TCA add the wizard like follows:
'module' => array(
'name' => 'wizard_geo_selector',
),
In ext_tables.php register the wizard.
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModulePath(
'wizard_geo_selector',
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Modules/Wizards/Yourwizardname/'
);
Keep in mind this is deprecated since Typo3 7 and removed in Typo3 8.So you can use this method upto Typo3 7.For Typo3 8 do use the method specified by David below.

symfony2 form field label as an array

I'd like to have 3 separate texts for each field in my form as a label. They are separate, because they need to be styled differently. I tried this:
$builder->add('total_sales', 'text', array(
'label' => array('num' => '1', 'descr' => 'Total sales', 'category' => 'A'),
'required' => false,
'attr' => array(
'class' => 'field numeric_field',
'maxlength' => 10,
)));
Obviously the above don't work; it will display 'Array' in place of label.
How can I achieve desired effect?
first you'll need to create a custom form type that extends the text type, the reason for this is so you don't mess up other text types you might have elsewhere. After doing that you'll need to style it using a form_div_layout. you can see the details here:
http://symfony.com/doc/current/cookbook/form/form_customization.html