Skip to content

Instantly share code, notes, and snippets.

@froemken
Last active June 14, 2021 06:21
Show Gist options
  • Save froemken/b89b62ef2615f4e4f0855724612d0abb to your computer and use it in GitHub Desktop.
Save froemken/b89b62ef2615f4e4f0855724612d0abb to your computer and use it in GitHub Desktop.
TYPO3 admin_get_fields with Doctrine QueryBuilder
<?php
declare(strict_types=1);
/*
* This file is part of the package jweiland/maps2.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
namespace JWeiland\Maps2\Utility;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Column;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* A little helper to organize our DB queries
*/
class DatabaseUtility
{
/**
* Get column definitions from table
* This is a alternative for TYPO3's DatabaseConnection :: admin_get_fields
*
* @param string $tableName
* @return array|Column[]
*/
public static function getColumnsFromTable(string $tableName): array
{
$columns = [];
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName);
if ($connection->getSchemaManager() instanceof AbstractSchemaManager) {
$columns = $connection->getSchemaManager()->listTableColumns($tableName);
}
return $columns;
}
}
@sbusemann
Copy link

nice work, I will use this function for http://github.com/in2code-de/t3am

@froemken
Copy link
Author

froemken commented Feb 11, 2021

@sbusemann
In the meantime I use something like:

            $connection = $this->getConnectionPool()->getConnectionForTable($tableName);
            $tables = $connection->getSchemaManager()->listTableColumns($tableName);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment