<?php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

defined('TYPO3') || die();

$tempColumnstx_igreservations_fe_users = [];
if (!isset($GLOBALS['TCA']['fe_users']['ctrl']['type'])) {
    // no type field defined, so we define it here. This will only happen the first time the extension is installed!!
    $GLOBALS['TCA']['fe_users']['ctrl']['type'] = 'tx_extbase_type';
    $tempColumnstx_igreservations_fe_users[$GLOBALS['TCA']['fe_users']['ctrl']['type']] = [
        'exclude' => true,
        'label'   => 'LLL:EXT:ig_reservations/Resources/Private/Language/locallang_db.xlf:tx_igreservations.tx_extbase_type',
        'config' => [
            'type' => 'select',
            'renderType' => 'selectSingle',
            'items' => [
                ['',''],
                ['FeUser','Tx_IgReservations_FeUser']
            ],
            'default' => 'Tx_IgReservations_FeUser',
            'size' => 1,
            'maxitems' => 1,
        ]
    ];
}
$tempColumnstx_igreservations_fe_users['purposes'] = [
    'exclude' => true,
    'l10n_mode' => 'exclude',
    'label'   => 'LLL:EXT:ig_reservations/Resources/Private/Language/locallang_db.xlf:fe_users.purposes',
    'config' => [
        'type' => 'select',
        'renderType' => 'selectMultipleSideBySide',
        'foreign_table' => 'tx_igreservations_domain_model_purpose',
        'maxitems' => 9999,
    ]
];
ExtensionManagementUtility::addTCAcolumns('fe_users', $tempColumnstx_igreservations_fe_users);

ExtensionManagementUtility::addToAllTCAtypes(
    'fe_users',
    $GLOBALS['TCA']['fe_users']['ctrl']['type'],
    '',
    'after:' . $GLOBALS['TCA']['fe_users']['ctrl']['label']
);

ExtensionManagementUtility::addToAllTCAtypes(
    'fe_users',
    'purposes',
    '',
    'after:' . $GLOBALS['TCA']['fe_users']['ctrl']['type']
);

/* inherit and extend the show items from the parent class */
if (isset($GLOBALS['TCA']['fe_users']['types']['0']['showitem'])) {
    $GLOBALS['TCA']['fe_users']['types']['Tx_IgReservations_FeUser']['showitem'] = $GLOBALS['TCA']['fe_users']['types']['0']['showitem'];
} elseif(is_array($GLOBALS['TCA']['fe_users']['types'])) {
    // use first entry in types array
    $fe_users_type_definition = reset($GLOBALS['TCA']['fe_users']['types']);
    $GLOBALS['TCA']['fe_users']['types']['Tx_IgReservations_FeUser']['showitem'] = $fe_users_type_definition['showitem'];
} else {
    $GLOBALS['TCA']['fe_users']['types']['Tx_IgReservations_FeUser']['showitem'] = '';
}
$GLOBALS['TCA']['fe_users']['types']['Tx_IgReservations_FeUser']['showitem'] .= ',--div--;LLL:EXT:ig_reservations/Resources/Private/Language/locallang_db.xlf:tx_igreservations_domain_model_feuser,';
$GLOBALS['TCA']['fe_users']['types']['Tx_IgReservations_FeUser']['showitem'] .= '';

$GLOBALS['TCA']['fe_users']['columns'][$GLOBALS['TCA']['fe_users']['ctrl']['type']]['config']['items'][] = ['LLL:EXT:ig_reservations/Resources/Private/Language/locallang_db.xlf:fe_users.tx_extbase_type.Tx_IgReservations_FeUser','Tx_IgReservations_FeUser'];
