Skip to content

Commit

Permalink
[BUGFIX] Convert getPageOverlay hook into PSR-14 Event
Browse files Browse the repository at this point in the history
Converts getPageOverlay hook into PSR-14 Event

## How to test:

Make page with access set and extend to subpage is set. The page will not be indexed.

Fixes: #4151
Relates: #4152
  • Loading branch information
thomashohn authored and dkd-kaehm committed Sep 18, 2024
1 parent b5be2e1 commit fe7c9eb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Classes/IndexQueue/FrontendHelper/UserGroupDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequest;
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerResponse;
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
use TYPO3\CMS\Core\Domain\Access\RecordAccessGrantedEvent;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Domain\Repository\PageRepositoryGetPageHookInterface;
use TYPO3\CMS\Core\Domain\Repository\PageRepositoryGetPageOverlayHookInterface;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectPostInitHookInterface;
Expand All @@ -36,8 +36,7 @@ class UserGroupDetector implements
FrontendHelper,
SingletonInterface,
ContentObjectPostInitHookInterface,
PageRepositoryGetPageHookInterface,
PageRepositoryGetPageOverlayHookInterface
PageRepositoryGetPageHookInterface
{
/**
* Index Queue page indexer request.
Expand All @@ -62,17 +61,22 @@ class UserGroupDetector implements
protected ?SolrLogManager $logger = null;
// activation

/**
* All event listeners are only triggered if this flag is enabled.
*/
protected bool $activated = false;

/**
* Activates a frontend helper by registering for hooks and other
* resources required by the frontend helper to work.
*/
public function activate(): void
{
$this->activated = true;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['configArrayPostProc'][__CLASS__] = UserGroupDetector::class . '->deactivateTcaFrontendGroupEnableFields';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_checkEnableFields'][__CLASS__] = UserGroupDetector::class . '->checkEnableFields';

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][__CLASS__] = UserGroupDetector::class;
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPageOverlay'][__CLASS__] = UserGroupDetector::class;

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['postInit'][__CLASS__] = UserGroupDetector::class;
$this->logger = GeneralUtility::makeInstance(SolrLogManager::class, __CLASS__);
Expand Down Expand Up @@ -134,21 +138,19 @@ public function getPage_preProcess(
/**
* Modifies page records so that when checking for access through fe groups
* no groups or extendToSubpages flag is found and thus access is granted.
*
* @param array $pageInput Page record
* @param int $lUid Overlay language ID
* @param PageRepository $parent Parent \TYPO3\CMS\Core\Domain\Repository\PageRepository object
*/
public function getPageOverlay_preProcess(
&$pageInput,
&$lUid,
PageRepository $parent
): void {
if (!is_array($pageInput)) {
public function getPageOverlay_preProcess(RecordAccessGrantedEvent $event): void
{
if (!$this->activated) {
return;
}
if ($event->getTable() !== 'pages') {
return;
}
$pageInput = $event->getRecord();
$pageInput['fe_group'] = '';
$pageInput['extendToSubpages'] = '0';
$event->updateRecord($pageInput);
}

// execution
Expand Down
8 changes: 8 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,14 @@ services:
- name: event.listener
identifier: 'solr.index.PageIndexer.FrontendUserAuthenticator'

ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\UserGroupDetector:
autowire: true
tags:
- name: event.listener
identifier: 'solr.index.IndexQueue.FrontendHelper.getPageOverlay_preProcess'
method: 'getPageOverlay_preProcess'
event: TYPO3\CMS\Core\Domain\Access\RecordAccessGrantedEvent

ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\PageIndexer:
autowire: true
tags:
Expand Down

0 comments on commit fe7c9eb

Please sign in to comment.