-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Provide event NewsControllerOverrideSettingsEvent #2571
- Loading branch information
1 parent
c11b015
commit 4457696
Showing
5 changed files
with
150 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the "news" Extension for TYPO3 CMS. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace GeorgRinger\News\Event; | ||
|
||
use GeorgRinger\News\Controller\NewsController; | ||
|
||
final class NewsControllerOverrideSettingsEvent | ||
{ | ||
protected array $settings; | ||
protected array $tsSettings; | ||
protected NewsController $newsController; | ||
|
||
public function __construct(array $settings, array $tsSettings, NewsController $newsController) | ||
{ | ||
$this->settings = $settings; | ||
$this->tsSettings = $tsSettings; | ||
$this->newsController = $newsController; | ||
} | ||
|
||
public function getSettings(): array | ||
{ | ||
return $this->settings; | ||
} | ||
|
||
public function getTsSettings(): array | ||
{ | ||
return $this->tsSettings; | ||
} | ||
|
||
public function getNewsController(): NewsController | ||
{ | ||
return $this->newsController; | ||
} | ||
|
||
public function setSettings(array $settings): void | ||
{ | ||
$this->settings = $settings; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,8 @@ | ||
.. _events: | ||
|
||
====== | ||
Events | ||
====== | ||
|
||
Several events can be used to modify the behaviour of EXT:news. | ||
|
||
.. contents:: | ||
:local: | ||
:depth: 1 | ||
|
||
Events | ||
----- | ||
|
||
.. event_example_findDemanded: | ||
\GeorgRinger\News\Event\ModifyDemandRepositoryEvent | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
This event is very powerful, as it allows to modify the query used to fetch the news records. | ||
|
||
Example | ||
""""""" | ||
This examples 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`: | ||
|
||
.. code-block:: yaml | ||
YourVendor\YourExtkey\EventListener\ModifyDemandRepositoryEventListener: | ||
tags: | ||
- name: event.listener | ||
identifier: 'eventnews-modifydemandrepository' | ||
event: GeorgRinger\News\Event\ModifyDemandRepositoryEvent | ||
Now create the file ``Classes/EventListener/ModifyDemandRepositoryEventListener.php``: | ||
|
||
.. code-block:: 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); | ||
} | ||
} | ||
Controller/NewsController overrideSettings | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Use this evebt to change the final settings which are for building queries, for the template, ... | ||
|
||
Example | ||
""""""" | ||
This examples modifies the settings by changing the category selection. | ||
|
||
First, register your implementation in the file ``ext_localconf.php``: | ||
|
||
.. code-block:: php | ||
<?php | ||
defined('TYPO3') or die(); | ||
$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Controller/NewsController.php']['overrideSettings'][$_EXTKEY] | ||
= \YourVendor\Extkey\Hooks\NewsControllerSettings::class . '->modify'; | ||
Now create the file ``Classes/Hooks/NewsControllerSettings.php``: | ||
|
||
.. code-block:: php | ||
<?php | ||
namespace YourVendor\Extkey\Hooks; | ||
class NewsControllerSettings | ||
{ | ||
public function modify(array $params) | ||
{ | ||
$settings = $params['originalSettings']; | ||
$settings['categories'] = '2,3'; | ||
return $settings; | ||
} | ||
} | ||
.. hint:: Please change the vendor and extension key to your real life code. | ||
.. _hooks: | ||
|
||
===== | ||
Hooks | ||
===== | ||
|
||
ALl hooks of EXT:news have been deprecated and will be removed in next major versions. | ||
Please use one of the available events instead. |