Last active
June 14, 2021 06:21
-
-
Save froemken/b89b62ef2615f4e4f0855724612d0abb to your computer and use it in GitHub Desktop.
TYPO3 admin_get_fields with Doctrine QueryBuilder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
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
nice work, I will use this function for http://github.com/in2code-de/t3am