RecordAccessGrantedEvent

New in version 12.0: This event serves as replacement for the removed hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_checkEnableFields'].

This event can be used to either define whether record access is granted for a user, or to modify the record in question. In case the $accessGranted property is set (either true or false), the defined settings is directly used, skipping any further event listener as well as any further evaluation.

API

class TYPO3\CMS\Core\Domain\Access\RecordAccessGrantedEvent

Event to modify records to be checked against “enableFields”.

Listeners are able to grant access or to modify the record itself to continue to use the native access check functionality with a modified dataset.

isPropagationStopped()
Return type:bool
setAccessGranted(bool accessGranted)
Parameters:
  • $accessGranted (bool) – the accessGranted
getTable()
Return type:string
getRecord()
Return type:array
updateRecord(array record)
Parameters:
  • $record (array) – the record
getContext()
Return type:TYPO3\CMS\Core\Context\Context

Example

Registration of the Event in your extension’s Services.yaml:

EXT:my_extension/Configuration/Services.yaml
MyVendor\MyExtension\MyEventListener:
  tags:
    - name: event.listener
      identifier: 'my-extension/set-access-granted'

The corresponding event listener class:

EXT:my_extension/Classes/MyEventListener.php
use TYPO3\CMS\Core\Domain\Access\RecordAccessGrantedEvent;

class MyEventListener {

    public function __invoke(RecordAccessGrantedEvent $event): void
    {
        // Manually set access granted
        if ($event->getTable() === 'my_table' && ($event->getRecord()['custom_access_field'] ?? false)) {
            $event->setAccessGranted(true);
        }

        // Update the record to be checked
        $record = $event->getRecord();
        $record['some_field'] = true;
        $event->updateRecord($record);
    }
}