Documentation

Create a new table for the Configurations

Or copy link

Create a new table for the Configurations

Estimated reading: minutes 5 views

5 views
Min read
  1. To provide the extension configurations or extension settings, it is required to create an SQL table, TCA file, model file, repository, and persistence files.
  2. Follow the below steps to create the required files.

Create a new table for the Configurations

  1. Create a new table “tx_employee_domain_model_conf” for the configurations in the file employeeext_tables.sql.
  2. Add the code below to create the table
CREATE TABLE tx_employee_domain_model_conf ( 
imagelist int(11) unsigned DEFAULT '0',
imagedetail int(11) unsigned DEFAULT '0',
);

Create a TCA file for the conf table

1. Create the TCA file tx_employee_domain_model_conf.php and the file path is employeeConfigurationTCAtx_employee_domain_model_conf.php.

2. Add the code below to the file tx_employee_domain_model_conf.php

<?php
return [
    'ctrl' => [
        'title' => 'Employee Configutaion',
        'label' => 'imagelist',
        'tstamp' => 'tstamp',
        'crdate' => 'crdate',
        'versioningWS' => true,
        'label_alt_force' => true,
        'origUid' => 't3_origuid',
        'languageField' => 'sys_language_uid',
        'transOrigPointerField' => 'l10n_parent',
        'transOrigDiffSourceField' => 'l10n_diffsource',
        'delete' => 'deleted',
        'enablecolumns' => [
            'disabled' => 'hidden',
            'starttime' => 'starttime',
            'endtime' => 'endtime',
        ],
        'searchFields' => 'imagelist',
        'iconfile' => 'EXT:employee/Resources/Public/Icons/Extension.png',
        'security' => [
            'ignorePageTypeRestriction' => true,
        ],
    ],
    'types' => [
        '1' => [
            'showitem' => 'imagelist,imagedetail'
        ],
    ],
    'columns' => [
        'sys_language_uid' => [
            'exclude' => true,
            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language',
            'config' => [
                'type' => 'language',
            ],
        ],
        'l10n_parent' => [
            'displayCond' => 'FIELD:sys_language_uid:>:0',
            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.l18n_parent',
            'config' => [
                'type' => 'select',
                'renderType' => 'selectSingle',
                'default' => 0,
                'items' => [
                    ['label' => '', 'value' => 0]
                ],
                'foreign_table' => 'tx_employee_domain_model_conf',
                'foreign_table_where' => 'AND {#tx_employee_domain_model_conf}.{#pid}=###CURRENT_PID### AND {#tx_employee_domain_model_conf}.{#sys_language_uid} IN (-1,0)',
            ],
        ],
        'l10n_diffsource' => [
            'config' => [
                'type' => 'passthrough',
            ],
        ],
        'hidden' => [
            'config' => [
                'type' => 'check',
                'items' => [
                    ['label' => 'Disable'],
                ],
            ]
        ],
        'starttime' => [
            'exclude' => true,
            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.starttime',
            'config' => [
                'type' => 'input',
                'renderType' => 'datetime',
                'eval' => 'datetime,int',
                'default' => 0,
                'behaviour' => [
                    'allowLanguageSynchronization' => true
                ]
            ],
        ],
        'endtime' => [
            'exclude' => true,
            'label' => 'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.endtime',
            'config' => [
                'type' => 'input',
                'renderType' => 'datetime',
                'eval' => 'datetime,int',
                'default' => 0,
                'range' => [
                    'upper' => mktime(0, 0, 0, 1, 1, 2038)
                ],
                'behaviour' => [
                    'allowLanguageSynchronization' => true
                ]
            ],
        ],
        'imagelist' => [
            'exclude' => 1,
            'label' => 'Show Image in List',
            'config' => [
                'type' => 'check',
                'items' => [ 
                    ['Show Image in List', ''],
                ],
            ]
        ],
        'imagedetail' => [
            'exclude' => 1,
            'label' => 'Show Image in Detail Page',
            'config' => [
                'type' => 'check',
                'items' => [ 
                    ['Show Image in Detail', ''],
                ],
            ]
        ],
    ],
];

Create the model for the conf table

  1. Let’s create the model file to fetch the records of the conf table.
  2. Create the model file Conf.php and the file path is employeeClassesDomainModelConf.php
  3. Add the code below to the model file
<?php

declare(strict_types=1);

namespace CompanyEmployeeDomainModel;

use TYPO3CMSExtbaseDomainObjectAbstractEntity;

/**
* Conf Model
*/
class Conf extends AbstractEntity
{
/**
* imagelist
*
* @var string
*/
protected $imagelist = '';

/**
* imagedetail
*
* @var string
*/
protected $imagedetail = '';


/**
* Returns the imagelist
*
* @return string
*/
public function getImagelist(): string
{
return $this->imagelist;
}

/**
* Sets the imagelist
*
* @param string $imagelist
* @return void
*/
public function setImagelist(string $imagelist): void
{
$this->imagelist = $imagelist;
}


/**
* Returns the imagedetail
*
* @return string
*/
public function getImagedetail(): string
{
return $this->imagedetail;
}

/**
* Sets the imagedetail
*
* @param string $imagedetail
* @return void
*/
public function setImagedetail(string $imagedetail): void
{
$this->imagedetail = $imagedetail;
}


}

Create a repository for the conf model

  1. Create the file ConfRepository.php, and the file path is employeeClassesDomainRepositoryConfRepository.php
  2. Add the code below to the file ConfRepository.php
<?php

declare(strict_types=1);

namespace CompanyEmployeeDomainRepository;

use TYPO3CMSExtbasePersistenceRepository;
use TYPO3CMSExtbasePersistenceGenericTypo3QuerySettings;
use TYPO3CMSCoreUtilityGeneralUtility;
use TYPO3CMSExtbasePersistenceGenericQuerySettingsInterface;

/**
* The repository for Employ
*/
class ConfRepository extends Repository
{
public function initializeObject()
{
/** @var QuerySettingsInterface $querySettings */
$querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
$querySettings->setRespectStoragePage(false);
$this->setDefaultQuerySettings($querySettings);
}
}
Share

Leave a Comment