Skip to content

Commit

Permalink
[FEATURE] Provide event CreateDemandObjectFromSettingsEvent #2567
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer committed Nov 22, 2024
1 parent 33cb657 commit c11b015
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 33 deletions.
6 changes: 6 additions & 0 deletions Classes/Controller/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use GeorgRinger\News\Domain\Repository\CategoryRepository;
use GeorgRinger\News\Domain\Repository\NewsRepository;
use GeorgRinger\News\Domain\Repository\TagRepository;
use GeorgRinger\News\Event\CreateDemandObjectFromSettingsEvent;
use GeorgRinger\News\Event\NewsCheckPidOfNewsRecordFailedInDetailActionEvent;
use GeorgRinger\News\Event\NewsDateMenuActionEvent;
use GeorgRinger\News\Event\NewsDetailActionEvent;
Expand Down Expand Up @@ -167,6 +168,11 @@ protected function createDemandObjectFromSettings(
GeneralUtility::callUserFunction($reference, $params, $this);
}
}

$event = new CreateDemandObjectFromSettingsEvent($demand, $settings, $class);
$this->eventDispatcher->dispatch($event);
$demand = $event->getDemand();

return $demand;
}

Expand Down
47 changes: 47 additions & 0 deletions Classes/Event/CreateDemandObjectFromSettingsEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/*
* 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\Domain\Model\Dto\NewsDemand;

final class CreateDemandObjectFromSettingsEvent
{
protected NewsDemand $demand;
protected array $settings;
protected string $class;

public function __construct(NewsDemand $demand, array $settings, string $class = '')
{
$this->demand = $demand;
$this->settings = $settings;
$this->class = $class;
}

public function getDemand(): NewsDemand
{
return $this->demand;
}

public function getSettings(): array
{
return $this->settings;
}

public function getClass(): string
{
return $this->class;
}

public function setDemand(NewsDemand $demand): void
{
$this->demand = $demand;
}

}
27 changes: 0 additions & 27 deletions Documentation/Tutorials/ExtendNews/Demands/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,6 @@ extending EXT:news. Read more about using a demand object in a custom
controller:
:ref:`Extension based on EXT:news: FilterController.php <extension_custom_controller>`.

Hooks
=====

Several hooks can be used to influence the demand object and its usage.

Hook findDemanded
-----------------

The hook :code:`findDemanded` is very
powerful. It allows to modify the query used to fetch the news records depending
on values set in the demand object. You can find an example of how to use it in
the chapter :ref:`Hooks: Example findDemanded <hooks_example_findDemanded>`.

Hook createDemandObjectFromSettings
-----------------------------------

The hook :code:`createDemandObjectFromSettings`
(:php:`$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['Controller/NewsController.php']['createDemandObjectFromSettings']`)
can be used to influence the settings of the demand object as it is used in
most standard actions in the :php:`NewsController`, such as the
:php:`listAction()`, :php:`selectedListAction()` and :php:`detailAction()`.

This hook can be used to insert settings from custom TypoScript or custom
FlexForm configuration into the demand object. (See also
:ref:`Extend FlexForms <extendFlexforms>`)


Events
======

Expand Down
12 changes: 6 additions & 6 deletions Documentation/Tutorials/ExtendNews/Hooks/Index.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.. _hooks:
.. _events:

=====
Hooks
=====
======
Events
======

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

.. contents::
:local:
:depth: 1

Hooks
Events
-----

.. event_example_findDemanded:
Expand Down Expand Up @@ -58,7 +58,7 @@ Now create the file ``Classes/EventListener/ModifyDemandRepositoryEventListener.
Controller/NewsController overrideSettings
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Use this hook to change the final settings which are for building queries, for the template, ...
Use this evebt to change the final settings which are for building queries, for the template, ...

Example
"""""""
Expand Down

0 comments on commit c11b015

Please sign in to comment.