PHP code example of xima / xima-typo3-recordlist

1. Go to this page and download the library: Download xima/xima-typo3-recordlist library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xima / xima-typo3-recordlist example snippets



// EXT:my_extension/Classes/Controller/UserController.php

namespace Vendor\MyExtension\Controller\Backend;

use Xima\XimaTypo3Recordlist\Controller\AbstractBackendController;
use Xima\XimaTypo3Recordlist\Dto\RecordSource;

class UserController extends AbstractBackendController
{
    public function getTableNames(): array
    {
        return ['fe_users'];
    }

    protected function getRecordSources(): array
    {
        return [new RecordSource(pid: 7, 

public function getTableNames(): array
{
    return ['be_users', 'be_groups', 'sys_filemounts'];
}


// EXT:my_extension/Configuration/Backend/Modules.php

use Vendor\MyExtension\Controller\Backend\UserController;

return [
    'my_extension_users' => [
        'parent' => 'web',
        'position' => ['after' => 'list'],
        'access' => 'user',
        'iconIdentifier' => 'content-text',
        'workspaces' => '*',
        'labels' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang_module.xlf',
        'extensionName' => 'MyExtension',
        'controllerActions' => [
            UserController::class => [
                'processRequest', // Required action
            ],
        ],
        'inheritNavigationComponentFromMainModule' => false,
    ],
];

class NewsController extends AbstractBackendController
{
    protected function getTemplateConfigurations(): array
    {
        return [
            'Default' => [
                'title' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:template.list',
                'icon' => 'actions-list',
            ],
            'Cards' => [
                'title' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:template.cards',
                'icon' => 'actions-menu',
                'actions' => ['templateSelection', 'newRecord'], // Only show template switcher and new record button
            ],
        ];
    }
}

protected function getTemplateConfigurations(): array
{
    $tableName = $this->getTableName();

    return match ($tableName) {
        'tx_news_domain_model_news' => [
            'Default' => ['title' => 'News List', 'icon' => 'actions-list'],
            'Cards' => ['title' => 'News Cards', 'icon' => 'actions-menu'],
        ],
        'tx_news_domain_model_tag' => [
            'Default' => ['title' => 'Tag List', 'icon' => 'actions-list'],
        ],
        default => [
            'Default' => ['title' => 'List', 'icon' => 'actions-list'],
        ],
    };
}

use Xima\XimaTypo3Recordlist\Controller\AbstractBackendController;
use Xima\XimaTypo3Recordlist\Dto\RecordSource;

class NewsController extends AbstractBackendController
{
    protected function getRecordSources(): array
    {
        return [
            new RecordSource(pid: 15, 

class UserController extends AbstractBackendController
{
    protected function modifyRecord(array &$record): void
    {
        // Add computed field
        $record['fullName'] = $record['first_name'] . ' ' . $record['last_name'];

        // Format date
        $record['formatted_date'] = date('Y-m-d', $record['crdate']);
    }
}

class NewsController extends AbstractBackendController
{
    protected function getDefaultFilters(): array
    {
        return [
            'author' => ['value' => 'Ruby Bennett', 'expr' => 'eq'],
        ];
    }
}

class NewsController extends AbstractBackendController
{
    protected function modifyTableConfiguration(): void
    {
        // Show categories filter even when the categories column is hidden
        $this->tableConfiguration['your-table-name']['columns']['categories']['filterVisible'] = true;
    }
}

class UserController extends AbstractBackendController
{
    protected function modifyQueryBuilder(): void
    {
        $body = $this->request->getParsedBody();

        // Add custom date filter
        if (!empty($body['register_date'])) {
            $registerDate = new \DateTime($body['register_date']);
            $this->additionalConstraints[] = $this->queryBuilder->expr()->gte(
                'register_date',
                $registerDate->getTimestamp()
            );
        }

        // Add custom status filter
        if (!empty($body['status'])) {
            $this->additionalConstraints[] = $this->queryBuilder->expr()->eq(
                'status',
                $this->queryBuilder->createNamedParameter($body['status'])
            );
        }
    }
}

class NewsController extends AbstractBackendController
{
    protected function modifyTableConfiguration(): void
    {
        $this->tableConfiguration['your-table-name']['columns']['fal_media']['defaultPosition'] = 2;
        $this->tableConfiguration['your-table-name']['columns']['author']['defaultPosition'] = 3;
        $this->tableConfiguration['your-table-name']['columns']['sitemap_changefreq']['defaultPosition'] = 4;
        $this->tableConfiguration['your-table-name']['columns']['sys_language_uid']['defaultPosition'] = 5;
        $this->tableConfiguration['your-table-name']['columns']['workspace-status']['defaultPosition'] = 6;
    }
}

class FilesController extends AbstractBackendController
{
    protected function modifyTableConfiguration(): void
    {
        // Hide icon column
        $this->tableConfiguration['sys_file_metadata']['showIconColumn'] = false;

        // Hide checkbox column
        $this->tableConfiguration['sys_file_metadata']['showCheckboxColumn'] = false;
    }
}

class NewsController extends AbstractBackendController
{
    protected function modifyTableConfiguration(): void
    {
        // Show UID column by default
        $this->tableConfiguration['tx_news_domain_model_news']['columns']['uid']['active'] = true;
        $this->tableConfiguration['tx_news_domain_model_news']['columns']['uid']['defaultPosition'] = 2;

        // Show PID column by default
        $this->tableConfiguration['tx_news_domain_model_news']['columns']['pid']['active'] = true;
        $this->tableConfiguration['tx_news_domain_model_news']['columns']['pid']['defaultPosition'] = 3;
    }
}

class UserController extends AbstractBackendController
{
    protected function modifyTableConfiguration(): void
    {
        // Enable inline editing for title field
        $this->tableConfiguration['your-table-name']['columns']['title']['partial'] = 'TextInlineEdit';

        // Enable inline editing for description
        $this->tableConfiguration['your-table-name']['columns']['description']['partial'] = 'TextInlineEdit';
    }
}

class UserController extends AbstractBackendController
{
    protected function modifyPaginatedRecords(): void
    {
        parent::modifyPaginatedRecords();

        foreach ($this->records as &$record) {
            // Add custom frontend URL
            $record['url'] = 'https://example.com/user/' . $record['uid'];
        }
    }
}