EventDispatcher (PSR-14 Events)¶
Register ClassifyContent Event Listener¶
Open your Services.yaml or Services.php file from your Extension.
Add the following code snippet to register the ClassifyContent event listener:
YourVendor\YourSitepackage\EventListner\ClassifyContent:
tags:
- name: event.listener
Handling the 'ClassifyContentEvent'¶
The ClassifyContent event listener handles the ClassifyContentEvent and performs custom logic.
Create a new PHP class in your TYPO3 extension, e.g., EXT:your_sitepackage/Classes/EventListner/ClassifyContent.php.
Implement the __invoke method in the class, which will handle the event. The method should accept a ClassifyContentEvent object as a parameter.
namespace YourVendor\YourSitepackage\EventListner;
use CodingFreaks\CfCookiemanager\Event\ClassifyContentEvent;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
class ClassifyContent
{
/**
* Handle the ClassifyContentEvent, handle the provider URL and set the service identifier.
*
* @param ClassifyContentEvent $event The ClassifyContentEvent object
*/
public function __invoke(ClassifyContentEvent $event): void
{
// Custom logic goes here
// Example: Dump a debug message
// DebuggerUtility::var_dump("SitePackage invoke");
// Example: Access the provider URL
// DebuggerUtility::var_dump($event->getProviderURL());
// Example: Set the service identifier
// $event->setServiceIdentifier("TESTServiceIdentifier");
}
}
Tip
Please note that you need to replace: YourVendorYourSitepackagewith the correct namespaces for your extension.