I'am working with Typo3 V8
And I need to add some extra fields in BE so a have created an extension that allow me to add extra fields and it's working fine.
My problem is
All the fields are showing in all pages
some fields shouldn't be appearing in all pages
For example my home page contain a slider so in BE I have fields for uploading images but in other pages I don't need these fields to be shown.
You could add a special doktype that has the extra fields.
Let's assume it will be doktype 163, then in ext_localconf.php add:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig(
'options.pageTree.doktypesToShowInNewPageDragArea := addToList(163)'
);
to add it to the list of page types above the pagetree.
In the same file register the icon for the doktype:
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Imaging\IconRegistry::class
)->registerIcon(
'apps-pagetree-mytype',
TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
[
'source' => 'EXT:' . $extKey . '/Resources/Public/Icons/Mytype.svg',
]
);
(Of course you need to add your svg image or use a different icon provider to register a bitmap)
In Configuration/TCA/Overrides/pages.php put:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'pages',
'doktype',
[
'Page type name',
163,
'apps-pagetree-mytype'
],
'1',
'after'
);
$GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][163] = 'apps-pagetree-mytype';
Instead of adding your custom fields with a call to \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes() you add them with:
$GLOBALS['TCA']['pages']['types'][163]['showitem'] =
$GLOBALS['TCA']['pages']['types'][\TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT]['showitem']
. 'the list with your new fields';
This basically copies the fields from the default page type and adds them to your custom doktype.
Of course it's nicer to have the name of the page type in an XLIFF file and to have the doktype number as a constant in your code, but that's for you to add.
Based on the doktype you can render whatever the new fields are for.
Hopefully this was the complete list of settings for adding a page type :-)
Related
I try to create my extension. The extension is called personal. So I use the personal_ prefix for the CType.
TYPO3 has version 11.5.23
For the dropdown, I think the only thing I have to do is to create the tt_content.php
I tried this guide:
https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/ContentElements/AddingYourOwnContentElements.html
Configuration/TCA/Overrides/tt_content.php
// Add the content element to the "Type" dropdown
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'Titel',
'personal_titel',
'content-text',
],
'textmedia',
'after'
);
But when I choose it from the wizard, the CType is unknown.
Had that behaviour once i had limited the allowed CEs of the content column (maybe you use grielements or sth elese).
I had to explicitly allow my CE in the content column config and after clearing the cache it worked. Maybe it helps in your case, too?
In order to have the full power of the TCA's showitem for configuring the back-end form for a plugin, I define it as a new CType, instead of a new list_type of the list CType.
I do this by registering it with addPlugin instead of the default method outlined in the official extension guide, using registerPlugin. In ext_tables.php:
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
[
// Label.
'LLL:EXT:my_ext/Resources/Private/Language/locallang.xlf:pi1.name',
// Plugin key.
'myext_pi1',
// Icon.
'pi1'],
'CType',
'my_ext'
);
Then I can just use, in Configuration/TCA/Overrides/tt_content.php:
$GLOBALS['TCA']['tt_content']['types']['myext_pi1'] = [
'showitem' => " ... "]
to configure it's back-end form display as I want.
But now, after successfully adding the plugin on a page from the back-end, when I try to view it from the front-end, I get the error:
ERROR: Content Element with uid "284" and type "myext_pi1" has no rendering definition!
It's not doing the usual: loading the controller action assigned to the plugin in ext_localconf.php with ExtensionUtility::configurePlugin (in ext_localconf.php).
Does anybody know what could I do to make it work?
The point in this case is, that the element does not just "act as if it were a custom content element", but it actually IS a custom content element.
So you will have to provide at least a basic configuration via
tt_content.myext_pi1
If you registered a plugin properly it might be enough to just copy the plugin configuration to the tt_content entry
tt_content.myext_pi1 < plugin.myext_pi1
I want to create a content element where the editor can chose an icon to display on the frontend.
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem(
'tt_content',
'CType',
[
'LLL:EXT:your_extension_key/Resources/Private/Language/Tca.xlf:yourextensionkey_newcontentelement',
'ServiceCE',
'example-registration',
],
'textmedia',
'after'
);
$GLOBALS['TCA']['tt_content']['types']['ServiceCE'] = [
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;;general,
header; Header,
bodytext;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:bodytext_formlabel,
',
];
Here I'm creating the layout on the back-end to insert the content, with just a header and a bodytext.
There would be a lot of possible solutions:
dependent whether the icon should be assigned to pages or content elements work with the table pages or tt_content
your extension will provied the list of icons:
add an additional field with a select list for the icons to the records. put it into TCA (Configuration/TCA/Override/<table>.php). Make sure the value is the icon-name, so you do not need additional replacements in FLUID.
Add the rendering to the FLUID template where it belongs. As it should be available everywhere the Layout-templates would be a good place.
use sys_categories:
use the build in categories for providing icons to any record.
create some categories with either the icon as category image or use another field as the icon name. (You even could add another field especially for the icon name.)
For the rendering of pages or tt_content add a data processor to get the assigned sys_category-records of the data record and then render the first/all icon(s) of the record in the Layout-templates.
I've special requirement on my project and I need help. I am using TYPO3 8.7.8. I've a custom extension to render tag labels in frontend. We can add the tags as TCA record in backend storage folder. In the TCA record, you can tag name. My requirement is, when I save the TCA record I want to create a TYPO3 page automatically with the same name as tag in a specific position. Everytime when I add a TCA record, I need to create corresponding page automatically. Is this possible? I can use hook while saving TCA. But is there any function to create pages automatically?
After automatic page creation, I want to insert a plugin content element in that page with a specific flexform value automatically. I know this is a strange requirement, but I would like to know if it is possible or not.
Exactly, you'd trigger a hook on saving and then as next step you can use the data handler to generate the new page (and possible content).
To create the page and content, use something like the following data structure
$data = [
'pages' => [
'NEW_1' => [
'pid' => 456,
'title' => 'Title for page 1',
],
],
'tt_content' => [
'NEW_123' => [
'pid' => 'NEW_1',
'header' => 'My content element',
],
],
];
Then call the datahandler with that structure:
$tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
$tce->stripslashes_values = 0;
$tce->start($data, []);
$tce->process_datamap();
Find out more in the docs at
https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Typo3CoreEngine/Database/Index.html#data-array
and
https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Typo3CoreEngine/UsingDataHandler/Index.html
Are you sure you need additional pages?
In general your problem sounds like you need one page where the plugin is inserted and where the plugin in dependency of an url-parameter (which can be converted with realurl into a path segment) shows only information depending of the selected record (tag).
If no tag is selected you can output a list with all available tags as a menu to navigate to all possible tags.
With a little effort (less than writing a hook like intended) you can add all tags to your menu.
I followed a tutorial to implement custom content elements in TYPO3. I don't understand how to configure backend fields.
Here is my override for tt_content:
$GLOBALS['TCA']['tt_content']['types']['my_custom_ce'] = [
'showitem' => '
--palette--;' . $frontendLanguageFilePrefix . 'palette.general;general,
--linebreak--, header;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:header_formlabel,
--linebreak--, date;Datum,
--linebreak--, media;Media,
--linebreak--, bodytext;text,
];
I would like for example to change the textarea size for the "bodytext" field. I read the official TCA reference but still don't get how this is working
The change of textarea fild size is done in
$GLOBALS['TCA']['tt_content']['columns']['bodytext']['config'] etc.
Look for details in the TCA reference.
This changes the field size for all CEs. As far as I know it is not possible to change this only for one CE.