b.imen
b.imen

Reputation: 127

Configure the Backend fields in typo3

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.

Upvotes: 0

Views: 789

Answers (1)

Jigal van Hemert
Jigal van Hemert

Reputation: 722

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 :-)

Upvotes: 2

Related Questions