简体   繁体   中英

TYPO3 Add new tab to page properties

I've wasted a full day trying to achieve this : what i want to do is to add a new tab (lets call it extralinks) to the page properties. and this tab will contain IRRE item to add links to every page so i created a new table :

ext_tables

CREATE TABLE links(
    uid int(11) NOT NULL auto_increment,
    link varchar(255) DEFAULT '' NOT NULL,
    PRIMARY KEY (uid)
);

and then i added a new file to TCA/Overrides/links.php

links.php

<?php
if (!defined('TYPO3_MODE')) {
    die ('Access denied.');
}

$GLOBALS['TCA']['links'] = array(
    'ctrl' => array(
        'label' => 'links',
        'title' => 'extralinks',
    ),
    'interface' => '',
    'columns' => array(
        'link' => array(
            'label' => 'extralinks',
            'exclude' => true,
            'config' => array(
                'type' => 'input',
                'size' => 50,
                'max' => 255,
                'eval' => 'trim'
            )
        )
    ),
    'types' => [
        '0' => [
            'showitem' => '
                --div--;;LLL:extralinks,
                link
            '
        ]
    ],
    'palettes' => 'extralinks'
);

$linksColumns = array(
    'extralinks' => array(
        'exclude' => true,
        'label' => 'extralinks',
        'config' => array(
            'type' => 'inline',
            'foreign_table' => 'links',
            'maxitems' => 30,
            'appearance' => [
                'collapseAll' => 1,
                'expandSingle' => 1,
            ],
        )
    )
);

now in the same file at the end i need to add this to have tables so i make the following:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('pages', '--div--;Extra links,extralinks;;;;1-1-1', '');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('pages', $linksColumns);

when i make this the new tab is there with the new item but when i try to add a link i will get an error which says extralinks doesnt is not a column in pages table -which is understandable-

so when i try this

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('links', '--div--;Extra links,extralinks;;;;1-1-1', '');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('links', $linksColumns);

now i dont even see the tab neither the item.... how can i achieve this ?

ps

  • forget the naming its different and i am pretty sure thats not the issue
  • i am using typo3-cms 9.5

First of all, as @Heinz Schilling says, you have to put the fields definition into TCA/Overrides/pages.php .

You must also put an "counter"-field to your pages table, so that TYPO3 knows you have irre elements inside this page.

In your ext_tables.sql you have to put following:

CREATE TABLE pages (
    extralinks int(11) unsigned DEFAULT '0' NOT NULL,
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM