Skip to content

Commit 12168f8

Browse files
committed
[TASK] Autowire ContentWhere with attribute
1 parent 17d2889 commit 12168f8

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

Classes/ServiceProvider.php

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use TYPO3\CMS\ContentBlocks\Definition\ContentType\PageTypeDefinition;
2727
use TYPO3\CMS\ContentBlocks\Definition\TableDefinitionCollection;
2828
use TYPO3\CMS\ContentBlocks\Registry\ContentBlockRegistry;
29-
use TYPO3\CMS\ContentBlocks\UserFunction\ContentWhere;
3029
use TYPO3\CMS\ContentBlocks\Utility\ContentBlockPathUtility;
3130
use TYPO3\CMS\Core\Core\Event\BootCompletedEvent;
3231
use TYPO3\CMS\Core\Database\Connection;
@@ -58,7 +57,6 @@ protected static function getPackageName(): string
5857
public function getFactories(): array
5958
{
6059
return [
61-
ContentWhere::class => static::getContentWhere(...),
6260
'content-blocks.icons' => static::getContentBlockIcons(...),
6361
'content-blocks.page-types' => static::getContentBlockPageTypes(...),
6462
'content-blocks.typoscript' => static::getContentBlockTypoScript(...),
@@ -79,19 +77,6 @@ public function getExtensions(): array
7977
] + parent::getExtensions();
8078
}
8179

82-
public static function getContentWhere(ContainerInterface $container): ContentWhere
83-
{
84-
$arrayObject = $container->get('content-blocks.parent-field-names');
85-
$parentFieldNames = $arrayObject->getArrayCopy();
86-
return self::new(
87-
$container,
88-
ContentWhere::class,
89-
[
90-
$parentFieldNames,
91-
]
92-
);
93-
}
94-
9580
public static function getContentBlockIcons(ContainerInterface $container): \ArrayObject
9681
{
9782
$arrayObject = new \ArrayObject();
@@ -200,16 +185,15 @@ public static function getContentBlockTypoScript(ContainerInterface $container):
200185
return $arrayObject;
201186
}
202187

203-
public static function getContentBlockParentFieldNames(ContainerInterface $container): \ArrayObject
188+
public static function getContentBlockParentFieldNames(ContainerInterface $container): array
204189
{
205-
$arrayObject = new \ArrayObject();
206190
$cache = $container->get('cache.core');
207191
$typoScriptFromCache = $cache->require('ContentBlocks_ParentFieldNames');
208192
if ($typoScriptFromCache !== false) {
209-
$arrayObject->exchangeArray($typoScriptFromCache);
210-
return $arrayObject;
193+
return $typoScriptFromCache;
211194
}
212195

196+
$arrayObject = [];
213197
/** @var TableDefinitionCollection $tableDefinitionCollection */
214198
$tableDefinitionCollection = $container->get(TableDefinitionCollection::class);
215199
$contentElementTable = ContentType::CONTENT_ELEMENT->getTable();
@@ -223,9 +207,9 @@ public static function getContentBlockParentFieldNames(ContainerInterface $conta
223207
$fieldNames[$foreignField] = $foreignField;
224208
}
225209
}
226-
$arrayObject->exchangeArray(array_values($fieldNames));
210+
$arrayObject = array_values($fieldNames);
227211
}
228-
$cache->set('ContentBlocks_ParentFieldNames', 'return ' . var_export($arrayObject->getArrayCopy(), true) . ';');
212+
$cache->set('ContentBlocks_ParentFieldNames', 'return ' . var_export($arrayObject, true) . ';');
229213
return $arrayObject;
230214
}
231215

@@ -241,8 +225,7 @@ public static function addTypoScript(ContainerInterface $container): \Closure
241225
public static function hideContentElementChildren(ContainerInterface $container): \Closure
242226
{
243227
return static function (ModifyDatabaseQueryForContentEvent $event) use ($container) {
244-
$arrayObject = $container->get('content-blocks.parent-field-names');
245-
$parentFieldNames = $arrayObject->getArrayCopy();
228+
$parentFieldNames = $container->get('content-blocks.parent-field-names');
246229
$queryBuilder = $event->getQueryBuilder();
247230
foreach ($parentFieldNames as $fieldName) {
248231
$queryBuilder->andWhere(
@@ -284,8 +267,7 @@ public static function recordSummaryForLocalization(ContainerInterface $containe
284267
{
285268
return static function (AfterRecordSummaryForLocalizationEvent $event) use ($container) {
286269
$recordsPerColumn = $event->getRecords();
287-
$arrayObject = $container->get('content-blocks.parent-field-names');
288-
$parentFieldNames = $arrayObject->getArrayCopy();
270+
$parentFieldNames = $container->get('content-blocks.parent-field-names');
289271
$allUids = [];
290272
foreach ($recordsPerColumn as $records) {
291273
foreach ($records as $record) {
@@ -361,7 +343,6 @@ public static function addEventListeners(ContainerInterface $container, Listener
361343
$listenerProvider->addListener(BootCompletedEvent::class, 'content-blocks.add-typoscript');
362344
$listenerProvider->addListener(ModifyDatabaseQueryForContentEvent::class, 'content-blocks.hide-content-element-children');
363345
$listenerProvider->addListener(AfterContentHasBeenFetchedEvent::class, 'content-blocks.hide-content-element-children-page-content-fetching');
364-
$listenerProvider->addListener(AfterRecordSummaryForLocalizationEvent::class, 'content-blocks.record-summary-for-localization');
365346
return $listenerProvider;
366347
}
367348
}

Classes/UserFunction/ContentWhere.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
namespace TYPO3\CMS\ContentBlocks\UserFunction;
1919

2020
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
21+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
2122
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
2223

2324
/**
@@ -27,6 +28,7 @@
2728
readonly class ContentWhere
2829
{
2930
public function __construct(
31+
#[Autowire(service: 'content-blocks.parent-field-names')]
3032
protected array $parentFieldNames
3133
) {}
3234

0 commit comments

Comments
 (0)