Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Wappler committed Nov 17, 2023
1 parent 5f8bef0 commit d350b55
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 192 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);

namespace WapplerSystems\A21glossary\EventListener;


use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;
use WapplerSystems\A21glossary\Processor;

final class AfterCacheableContentIsGeneratedEventListener
{
public function __invoke(AfterCacheableContentIsGeneratedEvent $event): void
{

$content = $event->getController()->content;


$tsConfig = GeneralUtility::makeInstance(ConfigurationManagerInterface::class)
->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);

$config = $tsConfig['plugin.']['tx_a21glossary.']['settings.'] ?? [];

$processor = GeneralUtility::makeInstance(Processor::class);
$event->getController()->content = $processor->main($content, $config);


}
}
83 changes: 0 additions & 83 deletions Classes/Hooks/FrontendHook.php

This file was deleted.

89 changes: 0 additions & 89 deletions Classes/Middleware/Glossary.php

This file was deleted.

36 changes: 19 additions & 17 deletions Classes/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function addSlashesOnArray(array &$theArray)
* @return string the modified content
* @throws \InvalidArgumentException
*/
public function main($content, $config = [])
public function main(string $content, array $config = []): string
{

$this->config = array_merge($this->config, $config);
Expand Down Expand Up @@ -397,7 +397,7 @@ public function main($content, $config = [])
* @param string $pidList idlists set by configuraion
* @return array glossary items
*/
protected function fetchGlossaryItems($pidList): array
protected function fetchGlossaryItems(string $pidList): array
{
// -1 means: ignore pids
if ('' === trim($pidList)) {
Expand All @@ -413,22 +413,24 @@ protected function fetchGlossaryItems($pidList): array

$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tx_a21glossary_main');

$query = $connection->createQueryBuilder()->select('*')->from('tx_a21glossary_main');
$query->where(
$query->expr()->in('pid', $aPidList),
$query->expr()->in('sys_language_uid', [-1, $languageUid])
)->orderBy('short', 'asc');

if ($statement = $query->execute()) {
foreach ($statement as $row) {
$row['shortcut'] = trim($row['shortcut']);
$row['short'] = trim($row['short']);
$items[$row['shortcut'] ? $row['shortcut'] : $row['short']] = $row;
if (!isset($this->count['found'])) {
$this->count['found'] = 0;
}
$this->count['found']++;
$query = $connection->createQueryBuilder();
$query->getRestrictions()->removeAll();
$query = $query->select('*')->from('tx_a21glossary_main')
->where(
$query->expr()->in('pid', $aPidList),
$query->expr()->in('sys_language_uid', [-1, $languageUid])
)
->orderBy('short', 'asc');

$results = $query->executeQuery()->fetchAllAssociative();
foreach ($results as $row) {
$row['shortcut'] = trim($row['shortcut']);
$row['short'] = trim($row['short']);
$items[$row['shortcut'] ? $row['shortcut'] : $row['short']] = $row;
if (!isset($this->count['found'])) {
$this->count['found'] = 0;
}
$this->count['found']++;
}
$this->count['used'] = \count($items);
return $items;
Expand Down
5 changes: 5 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ services:

WapplerSystems\A21glossary\:
resource: '../Classes/*'

WapplerSystems\A21glossary\EventListener\AfterCacheableContentIsGeneratedEventListener:
tags:
- name: event.listener
identifier: 'a21glossary/content-modifier'
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
"typo3/cms-frontend": "^12.4.0",
"georgringer/numbered-pagination": "^1.0.2"
},
"replace": {
"svewap/a21glossary": "self.version"
},
"extra": {
"typo3/cms": {
"extension-key": "a21glossary"
Expand Down

0 comments on commit d350b55

Please sign in to comment.