Events

Several events can be used to modify the behaviour of EXT:news.

Available events

Check out the Events reference.

Examples

Provide more variables to the view

To connect to an event, you need to register an event listener in your custom extension. All what it needs is an entry in your Configuration/Services.yaml file:

services:
  Vendor\Extension\EventListener\YourListener:
    tags:
      - name: event.listener
        identifier: 'your-self-choosen-identifier'
        method: 'methodToConnectToEvent'
        event: GeorgRinger\News\Event\NewsListActionEvent
Copied!

An example event listener can look like this:

<?php

declare(strict_types=1);

namespace Vendor\Extension\EventListener;

use GeorgRinger\News\Event\NewsListActionEvent;

class YourListener
{
    /**
     * Do what you want...
     */
    public function methodToConnectToEvent(NewsListActionEvent $event): void
    {
        $values = $event->getAssignedValues();

        // Do some stuff

        $event->setAssignedValues($values);
    }
}
Copied!

GeorgRingerNewsEventModifyDemandRepositoryEvent

This event is very powerful, as it allows to modify the query used to fetch the news records.

This example modifies the query and adds a constraint that only news records are shown which contain the word yeah.

First, register your implementation in the file Configuration/Services.yaml:

YourVendor\YourExtkey\EventListener\ModifyDemandRepositoryEventListener:
  tags:
    - name: event.listener
      identifier: 'eventnews-modifydemandrepository'
      event: GeorgRinger\News\Event\ModifyDemandRepositoryEvent
Copied!

Now create the file Classes/EventListener/ModifyDemandRepositoryEventListener.php:

<?php

namespace YourVendor\YourExtkey\EventListener;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use GeorgRinger\News\Event\ModifyDemandRepositoryEvent

class ModifyDemandRepositoryEventListener
{
    public function __invoke(ModifyDemandRepositoryEvent $event) {
        $constraints = $event->getConstraints();
        $constraints[] = $query->like('title', '%' . $subject . '%');
        $event->setConstraints($constraints);
    }
}
Copied!

Controller/NewsController overrideSettings

Use this event to change the final settings which are for building queries, for the template, ...

This example modifies the settings by changing the category selection.

First, register your implementation in the file Services/yaml:

YourVendor\YourExtkey\EventListener\NewsControllerOverrideSettingsEventListener:
  tags:
    - name: event.listener
      identifier: 'eventnews-modifysettings'
      event: GeorgRinger\News\Event\NewsControllerOverrideSettingsEvent
Copied!

Now create the file Classes/EventListener/NewsControllerOverrideSettingsEvent.php:

<?php

namespace YourVendor\Extkey\EventListener;

class NewsControllerOverrideSettingsEvent
{
    public function __invoke(\GeorgRinger\News\Event\NewsControllerOverrideSettingsEvent $event): array
    {
        $settings = $event->getSettings();
        $settings['categories'] = '2,3';

        $event->setSettings($settings);
    }
}
Copied!