Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/phpunit.functional.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" cacheResult="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="../vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php">
<source>
<include>
<directory>../Classes/</directory>
</include>
</source>
<testsuites>
<testsuite name="functional">
<directory suffix=".php">../Tests/Functional/</directory>
<exclude>../Tests/Functional/Fixtures/</exclude>
</testsuite>
</testsuites>
<php>
<const name="TYPO3_TESTING_FUNCTIONAL_REMOVE_ERROR_HANDLER" value="true"/>
<ini name="display_errors" value="1"/>
<env name="TYPO3_CONTEXT" value="Testing"/>
</php>
</phpunit>
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@ jobs:
bootstrap: vendor/autoload.php
configuration: .github/phpunit.xml

functional-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: mbstring, intl, pdo_sqlite
tools: composer:v2

- name: Composer install
run: composer install --ignore-platform-reqs --no-interaction

- name: Prepare TYPO3 extension path
run: |
mkdir -p public/typo3conf/ext/
if [ ! -L public/typo3conf/ext/webcomponents ]; then ln -snvf ../../../. public/typo3conf/ext/webcomponents; fi

- name: Functional Tests
env:
typo3DatabaseDriver: pdo_sqlite
typo3DatabaseName: typo3
run: vendor/bin/phpunit -c .github/phpunit.functional.xml

phpstan:
runs-on: ubuntu-latest
steps:
Expand Down
43 changes: 24 additions & 19 deletions Classes/DataProviding/Helpers/InlineItemsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand All @@ -25,49 +24,55 @@ public function __construct(
) {}

/**
* @param array<string, string|integer> $parentRecord
* @return list<array<string, string|integer>>
* @param array<string, int|string> $parentRecord
* @return list<array<string, int|string>>
*/
public function loadInlineItems(array $parentRecord, string $inlineFieldName, string $parentTable = 'tt_content'): array
{
// if the field is empty, and we're not in a workspace context, then there are no inline items
/** @var int|string $versioningWorkspaceId */
$versioningWorkspaceId = $this->context->getPropertyFromAspect('workspace', 'id');
$versioningWorkspaceId = (int)$versioningWorkspaceId;
$workspaceId = $this->context->getPropertyFromAspect('workspace', 'id');
$versioningWorkspaceId = is_int($workspaceId) || is_string($workspaceId) ? (int)$workspaceId : 0;
if (empty($parentRecord[$inlineFieldName]) && $versioningWorkspaceId === 0) {
return [];
}

$inlineFieldTca = $this->getInlineFieldTca($inlineFieldName, $parentTable);
$foreignTable = $inlineFieldTca['config']['foreign_table'] ?? null;
if ($foreignTable === null) {
$inlineFieldConfig = $inlineFieldTca['config'] ?? [];
$foreignTable = $inlineFieldConfig['foreign_table'] ?? null;
if (!is_string($foreignTable) || $foreignTable === '') {
throw new \Exception(
sprintf('Could not load inline items for field "%s". Missing \'foreign_table\' in its TCA configuration', $inlineFieldName),
1686299043
);
}
$foreignField = $inlineFieldTca['config']['foreign_field'] ?? null;
$foreignTableTca = $GLOBALS['TCA'][$foreignTable];
$foreignSortby = $inlineFieldTca['config']['foreign_sortby'] ?? $foreignTableTca['ctrl']['sortby'] ?? null;
$foreignField = $inlineFieldConfig['foreign_field'] ?? null;
if (!is_string($foreignField) || $foreignField === '') {
$foreignField = null;
}
$foreignTableTca = $GLOBALS['TCA'][$foreignTable] ?? [];
$foreignSortby = $inlineFieldConfig['foreign_sortby'] ?? $foreignTableTca['ctrl']['sortby'] ?? null;
if (!is_string($foreignSortby) || $foreignSortby === '') {
$foreignSortby = null;
}
$queryBuilder = $this->connectionPool->getQueryBuilderForTable($foreignTable);
$queryBuilder->getRestrictions()->removeAll();

$parentRecordId = $parentRecord['_LOCALIZED_UID'] ?? $parentRecord['uid'] ?? 0;
$constraints = [];
$constraints = $this->pageRepository->getDefaultConstraints($foreignTable);
if (!empty($foreignField)) {
$constraints[] = $queryBuilder->expr()->eq($foreignField, $queryBuilder->createNamedParameter($parentRecordId, Connection::PARAM_INT));
$constraints['foreign_field'] = $queryBuilder->expr()->eq($foreignField, $queryBuilder->createNamedParameter($parentRecordId, Connection::PARAM_INT));
} else {
$itemsUidList = GeneralUtility::intExplode(',', (string)($parentRecord[$inlineFieldName] ?? ''), true);
if (empty($itemsUidList)) {
return [];
}
$constraints[] = $queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($itemsUidList, ArrayParameterType::INTEGER));
$constraints['uidList'] = $queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($itemsUidList, ArrayParameterType::INTEGER));
}
if (isset($foreignTableTca['ctrl']['languageField'])) {
$constraints[] = $queryBuilder->expr()->in($foreignTableTca['ctrl']['languageField'], $queryBuilder->createNamedParameter([-1, $parentRecord['sys_language_uid'] ?? 0], ArrayParameterType::INTEGER));
$languageField = $foreignTableTca['ctrl']['languageField'] ?? null;
if (is_string($languageField) && $languageField !== '') {
$constraints['language'] = $queryBuilder->expr()->in($languageField, $queryBuilder->createNamedParameter([-1, $parentRecord['sys_language_uid'] ?? 0], ArrayParameterType::INTEGER));
}
$constraints[] = QueryHelper::stripLogicalOperatorPrefix($this->pageRepository->enableFields($foreignTable));
$queryBuilder->select('*')->from($foreignTable)->where(...$constraints);
$queryBuilder->select('*')->from($foreignTable)->where(...array_values($constraints));
if ($foreignSortby) {
$queryBuilder->orderBy($foreignSortby);
}
Expand Down Expand Up @@ -96,7 +101,7 @@ public function loadInlineItems(array $parentRecord, string $inlineFieldName, st
}

/**
* @return array{config: array{foreign_table?: string, foreign_field?: string, foreign_sortby?: string}, label: string, type: string}
* @return array{config?: array<string, mixed>}
*/
protected function getInlineFieldTca(string $inlineFieldName, string $localTableName = 'tt_content'): array
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","sys_language_uid","input_1","sorting"
,"1","1","1","tx_inlineitemshelperfixture_parent","-1","BJB","2"
,"2","1","1","tx_inlineitemshelperfixture_parent","-1","BJB","1"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","sys_language_uid","input_1","t3ver_wsid","t3ver_state","sorting"
,"1","1","1","tx_inlineitemshelperfixture_parent","-1","BJB","1","1","2"
,"2","1","1","tx_inlineitemshelperfixture_parent","-1","BJB","1","1","1"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","input_1","t3ver_wsid","t3ver_state","sorting"
,"1","1","1","tx_inlineitemshelperfixture_parent","BJB","0","0","2"
,"2","1","1","tx_inlineitemshelperfixture_parent","BJB","0","0","3"
,"3","1","1","tx_inlineitemshelperfixture_parent","BJB","1","1","1"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","input_1","t3ver_wsid","t3ver_state","sorting"
,"1","1","1","1","-1","BJB","0","0","2"
,"2","1","1","1","-1","BJB","0","0","3"
,"3","1","1","1","-1","BJB","1","1","4"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","input_1","t3ver_wsid","t3ver_state","sorting"
,"1","1","1","tx_inlineitemshelperfixture_parent","BJB","0","0","2"
,"2","1","1","tx_inlineitemshelperfixture_parent","BJB","0","0","5"
,"3","1","1","tx_inlineitemshelperfixture_parent","BJB","1","1","4"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","input_1","t3ver_wsid","t3ver_state","t3ver_oid","sorting"
,"1","1","1","tx_inlineitemshelperfixture_parent","BJB","0","0","0","3"
,"2","1","1","tx_inlineitemshelperfixture_parent","BJB","0","0","0","2"
,"3","1","1","tx_inlineitemshelperfixture_parent","BJB","1","2","1","3"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","sys_language_uid","input_1","sorting","t3ver_oid","t3ver_wsid"
,"1","1","1","1","-1","BJB/first","1","0","0"
,"2","1","1","1","-1","BJB/second","2","0","0"
,"3","1","1","1","-1","BJB/first","2","1","1"
,"4","1","1","1","-1","BJB/second","1","2","1"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","sys_language_uid","input_1"
,"1","1","1","tx_inlineitemshelperfixture_parent","-1","BJB"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","sys_language_uid","input_1","t3ver_wsid","t3ver_state","t3ver_oid"
,"1","1","1","tx_inlineitemshelperfixture_parent","-1","BJB","0","0","0"
,"2","1","1","tx_inlineitemshelperfixture_parent","-1","BJB/changed","1","0","1"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","sys_language_uid","hidden","t3ver_wsid","t3ver_state","t3ver_oid"
,"1","1","1","1","-1","1","0","0","0"
,"2","1","1","1","-1","0","1","0","1"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","sys_language_uid","input_1","t3ver_wsid","t3ver_state"
,"1","1","1","1","-1","BJB","1","1"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","sys_language_uid","input_1"
,"1","1","2","tx_inlineitemshelperfixture_parent","1","BJB"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"tx_inlineitemshelperfixture_child"
,"uid","pid","parentid","parenttable","sys_language_uid","input_1"
,"1","1","1","tx_inlineitemshelperfixture_parent","0","BJB"
,"2","1","2","tx_inlineitemshelperfixture_parent","1","BJB/overlaid"

"tx_inlineitemshelperfixture_parent"
,"uid"
,"1"
Loading