TYPO3 BE TCA type Preview Image - php

i search for a Solution:
How can i add a Preview Image for a TCA type?
Example: I have 3 different types and would like to display a preview image for them. The same as the t3 backend layouts.
Just like the Backend-Layout:
Maybe there is a solution to this?

The documentation is explaining it:
https://docs.typo3.org/m/typo3/reference-tca/main/en-us/Columns/Examples.html#select-drop-down-for-records-represented-by-images
This is the example code:
[
'columns' => [
'select_single_12' => [
'label' => 'select_single_12 foreign_table selicon_field',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'foreign_table' => 'tx_styleguide_elements_select_single_12_foreign',
'fieldWizard' => [
'selectIcons' => [
'disabled' => false,
],
],
],
],
],
]
And the code for the field of the connected table is this:
[
'ctrl' => [
'title' => 'Form engine elements - select foreign single_12',
'label' => 'fal_1',
'selicon_field' => 'fal_1',
// ...
],
'columns' => [
// ...
'fal_1' => [
'label' => 'fal_1 selicon_field',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'fal_1',
[
'maxitems' => 1,
],
$GLOBALS['TYPO3_CONF_VARS']['SYS']['mediafile_ext']
),
],
],
// ...
];
As you have a strange label inside your field it's not clear if you want to link to an image, to a text or even to a field that offers a combination like it's done with relations to the table sys_file by the intermediate table sys_file_ref.
So defining more precise what you need exactly might help to give you a more detailed answer. You can edit your answer to add this description.

Related

Add TYPO3 palette to all elements?

I have made a custom palette in tt_content.php and want to add it to all content elements on the appearance tab like this:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tt_content',
'--palette--;My Palette;my_palette',
'',
'before:sectionIndex'
);
This works for everything except Grid Elements (gridelements_pi1). How do I make the new palette show up on Grid Elements as well?
The comment from #MathiasBrodala lead me to finding the answer is in the order of extensions.
In this case I needed to add gridelements under suggests in my ext_emconf.php which ensures it will be loaded before my site package.
$EM_CONF[$_EXTKEY] = [
'title' => 'My Package',
'description' => 'TYPO3 Sitepackage',
'category' => 'templates',
'version' => '1.0.0',
'state' => 'stable',
'constraints' => [
'depends' => [
'typo3' => '8.7.0-9.5.99',
'fluid_styled_content' => '8.7.0-9.5.99'
],
'suggests' => [
'gridelements' => '9.3.0-0.0.0',
],
'conflicts' => [
],
],
'uploadfolder' => 0,
'createDirs' => '',
'clearCacheOnLoad' => 1
];

Populate label or attribute of form element in Zend Framework 3

I'm still fairly new to ZF3 so forgive me if I'm asking an obvious question here, but after many searches, looks through the source and head scratching, I can't seem to find an obvious approach to populating label text with data from the entity.
Basically, I have a form collection containing form elements which are each stored with a type (ID), e.g. "Business phone", "Mobile phone", etc.
Is there a way to populate anything other than a value in a form element?
Edit (more info)
So, there is a PersonForm, with a Person Fieldset which contains a Phone Fieldset collection:
$phoneFieldset = new PhoneFieldset($objectManager);
$this->add([
"type" => Element\Collection::class,
"name" => "Phones",
"options" => [
"count" => 0,
"should_create_template" => true,
"allow_add" => true,
"allow_remove" => true,
"target_element" => $phoneFieldset
],
]);
This Phone fieldset contains the following elements:
$this->add([
"name" => "Type_ID",
"type" => "hidden",
]);
$this->add([
"name" => "Number",
"type" => "text",
"attributes" => [
"placeholder" => "Enter phone number",
],
"options" => [
"label" => "Email" // Ideally this would be $entity->getTypeName() for example, which would return the name based on the Type_ID mapped against a constant
]
]);
Sure, adding label information for a formCollection (Fieldset or Collection elements) is pretty much the same as for input elements (Element) (Element docs).
Some examples:
Add a Fieldset into a Form ($this->formCollection($form->get('address'))):
Docs: https://docs.zendframework.com/zend-form/element/collection/
$this->add(
[
'type' => AddressFieldset::class, // Note: FQCN -> provided by FormElementManager
'name' => 'address',
'required' => true,
'options' => [
'use_as_base_fieldset' => false,
'label' => _('Address'),
'label_options' => [
// .. add options for the label, see LabelInterface
],
'label_attributes' => [
// .. add attributes for the label, see LabelInterface
],
],
]
);
Renders as:
<fieldset>
<legend>Address</legend>
<!-- the inputs / labels of `Element` objects -->
</fieldset>
Add a Collection into a Form ($this->formCollection($form->get('cities'))):
Docs: https://docs.zendframework.com/zend-form/element/collection/
$this->add(
[
'name' => 'cities',
'type' => Collection::class,
'options' => [
'label' => _('Cities'),
'should_create_template' => true,
'allow_add' => true,
'allow_remove' => true,
'count' => 1,
'target_element' => $this->getCityFieldset(), // Must be an instantiated Fieldset (so provide via Factory)
'label_options' => [
// .. add options for the label, see LabelInterface
],
'label_attributes' => [
// .. add attributes for the label, see LabelInterface
],
],
'attributes' => [
'class' => 'fieldset-collection',
'data-fieldset-name' => _('City'),
],
]
);
Renders as:
<fieldset class="fieldset-collection" data-fieldset-name="City">
<legend>Cities</legend>
<fieldset><!-- add a <legend> using JS here, with the data-fieldset-name of the parent -->
<!-- the inputs / labels of `Element` objects -->
</fieldset>
<span data-template="<!-- contains entire template so you can use JS to create 'add' and 'remove' buttons for additional CityFieldset <fieldset> elements -->"></span>
</fieldset>
I added in the <!-- comments --> in the HTML output, you can figure those out ;-)
Additionally, if you're using an ORM, Doctrine in this example, then you could do it like this:
$this->add(
[
'name' => 'roles',
'required' => true,
'type' => ObjectMultiCheckbox::class,
'options' => [
'object_manager' => $this->getObjectManager(),
'target_class' => Role::class,
'property' => 'id',
'label' => _('Roles'),
'label_generator' => function ($targetEntity) {
/** #var Role $targetEntity */
return $targetEntity->getName();
},
'label_options' => [
'label_position' => FormRow::LABEL_APPEND,
],
'use_hidden_element' => true,
'checked_value' => 1,
'unchecked_value' => 0,
],
'attributes' => [
'class' => 'form-check-input',
],
]
);
Doctrine Form Elements docs

TYPO3 How to add Create new button on TCA?

I would like to build a slider (Own Content Element). So on the backend i would like to have a section with multiple records. What do i mean? By clicking the "Create new" i would like to have an image selection and rich text selection.
Something like that.
How can i achieve this?
So far i have:
TCA/Overrides/tt_content.php
which gives me the rich editor and the image selection in backend, but not grouped.
$GLOBALS['TCA']['tt_content']['types']['my_slider'] = array( 'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.headers;headers,bodytext,assets;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
]
]
);
tt_content.typosript
tt_content {
my_slider < lib.contentElement
my_slider {
templateRootPaths.10 = {$Private}Templates/
templateName = Slider.html
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = assets
as = images
}
}
}
}
Slider.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<h1>{data.header}</h1>
<p>{data.bodytext}</p>
<f:for each="{images}" as="image">
<f:image image="{image}" alt="{file.properties.alt}" cropVariant="desktop"/>
{image.description}
</f:for>
<f:debug>{data}</f:debug>
</html>
Now with the current code i get the results in frontend. One Text and one Image. But how can i get it as group after configured it on the backend?
You need add new field to the sys_file_reference TCA:
Configuration/TCA/Overrides/sys_file_reference.php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'sys_file_reference',
[
'tx_myext_description' => [
'label' => 'My field description',
'config' => [
'type' => 'text',
'cols' => '80',
'rows' => '15',
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
],
]
);
ext_tables.sql
CREATE TABLE sys_file_reference (
tx_myext_description mediumtext,
);
Remember to add new field into database (using database compare tool in install tool).
Then use it in TCA of your new slider:
Configuration/TCA/Overrides/tt_content.php
$GLOBALS['TCA']['tt_content']['types']['my_slider'] = [
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.headers;headers,bodytext,assets;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
],
'assets' => [
'config' => [
'overrideChildTca' => [
'types' => [
0 => ['showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][0]['showitem'].',tx_myext_description'],
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO]['showitem'].',tx_myext_description'
],
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION]['showitem'].',tx_myext_description'
],
],
],
],
],
],
];
And then your Fluid template may look like that:
Slider.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<h1>{data.header}</h1>
<p>{data.bodytext}</p>
<f:for each="{images}" as="image">
<f:image image="{image}" alt="{file.properties.alt}" cropVariant="desktop"/>
{image.properties.tx_myext_description -> f:format.html()}
</f:for>
</html>

TYPO3 how to add virtual column to the TCA?

how can I add an virtual column to the TCA (TYPO3 8)? I have in a 1:n table with data and I want to display the count of the data in the backend to current element.
I need something like this:
$fields = [
'counts7d' => [
'exclude' => false,
'label' => 'last 7 days',
'config' => [
'type' => 'none',
'procFunc' => '\Namespace\MyClass->MyMethod',
'readOnly' => true,
'params' => [
'period => '7d'
]
]
],
'counts30d' => [
'exclude' => false,
'label' => 'last 30 days',
'config' => [
'type' => 'none',
'procFunc' => '\Namespace\MyClass->MyMethod',
'readOnly' => true,
'params' => [
'period => '30d'
]
]
],
];
pseudo function:
public function myMethod($element, $params){
$sql = "SELECT count(*) FROM TABLE WHERE pid=$element[uid] and date > $params[period]";
return sql_count…
}
The field should only be informative for the backend users.
Does anyone have an idea?
Thanks
Oliver
The TCA field type user is exactly what you are looking for:
'counts7d' => [
'exclude' => false,
'label' => 'last 7 days',
'config' => [
'type' => 'user',
'userFunc' => \Namespace\MyClass::class . '->MyMethod',
'parameters' => [
'period => '7d',
],
],
],
The TCA field type none is exactly what you are looking for. Type none is the only type that does not necessarily need a database field. To manipulate it you can use userFunc which allow you to use custom php function.

zend framework 3 Select tag validation

I am getting the error:
The input was not found in the haystack
After form post. Please see the selection tag code lines below:
// Add "roles" field
$this->add([
'type' => 'select',
'name' => 'roles',
'attributes' => [
'multiple' => 'multiple',
'options'=>$this->role_desc,
'inarrayvalidator' => false,
'class'=>'form-control'
],
'options' => [
'label' => 'Role(s)',
],
]);
// Add input for "roles" field
$inputFilter->add([
'class' => ArrayInput::class,
'name' => 'roles',
'required' => true,
'haystack'=>$this->role_ids,
'filters' => [
['name' => 'ToInt'],
],
'validators' => [
['name'=>'GreaterThan', 'options'=>['min'=>1]],
['name'=>'InArray', 'options'=>['haystack'=>$this-
>role_ids]]
],
]);
The InArray seems to be validating well, lm just no sure what is bringing up the exception. Thank you in advance.
Actually , your issue is similar to link
To solve this, change your validators definition to:
'validators' => [
['name'=>'GreaterThan', 'options'=>['min'=>1]],
[
'name' => 'Explode',
'options' => array(
'validator' => [
'name'=>'InArray',
'options'=> [
'haystack'=>$this->role_ids
]
]
)
]
],
Unfortunately, I do not think there is a "cleaner" way to do this.
Alternately, Maybe you could use the MultiCheckbox.

Categories