Skip to content

Commit affe759

Browse files
authored
Update event listener example #3155 (#5750)
1 parent ec6f0d4 commit affe759

File tree

4 files changed

+35
-52
lines changed

4 files changed

+35
-52
lines changed

Documentation/ExtensionArchitecture/HowTo/Events/Index.rst

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,9 @@ the name in the :file:`Configuration/Services.yaml` or it is not found.
3030
It is best practice to use a descriptive class name and to put it in the
3131
namespace :php:`MyVendor\MyExtension\EventListener`.
3232

33-
.. note::
34-
This example is outdated as the used event :ref:`PasswordChangeEvent`
35-
does not provide the method :php:`setAsInvalid()` anymore. However, it
36-
illustrates the basic principle of an event listener.
37-
38-
.. todo: Adjust example, see also https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/issues/3155
39-
40-
.. literalinclude:: _Joh316PasswordInvalidator.php
33+
.. literalinclude:: _Joh316PasswordInformer.php
4134
:language: php
4235

43-
Then register the event in your extension's :file:`Configuration/Services.yaml`:
44-
45-
.. literalinclude:: _EventServices.yaml
46-
:language: yaml
47-
48-
Additionally, the :file:`Configuration/Services.yaml` file allows to define a different
49-
method name for the event listener class and to influence the order in which
50-
events are loaded. See :ref:`EventDispatcherRegistration` for details.
51-
5236
Dispatch an event
5337
=================
5438

Documentation/ExtensionArchitecture/HowTo/Events/_EventServices.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
// EXT:my_extension/Classes/EventListener/Joh316PasswordInformer.php
4+
declare(strict_types=1);
5+
6+
namespace MyVendor\MyExtension\EventListener;
7+
8+
use Psr\Log\LoggerInterface;
9+
use TYPO3\CMS\Core\Attribute\AsEventListener;
10+
use TYPO3\CMS\FrontendLogin\Event\PasswordChangeEvent;
11+
12+
/**
13+
* The password 'joh316' was historically used as the default password for
14+
* the TYPO3 install tool.
15+
* Today this password is an unsecure choice as it is well-known, too short
16+
* and does not contain capital letters or special characters.
17+
*/
18+
#[AsEventListener]
19+
final class Joh316PasswordInvalidator
20+
{
21+
public function __construct(
22+
private readonly LoggerInterface $logger,
23+
) {}
24+
25+
public function __invoke(PasswordChangeEvent $event): void
26+
{
27+
if ($event->getRawPassword() === 'joh316') {
28+
$this->logger->warning(sprintf(
29+
'User %s uses the default password "joh316".',
30+
$event->getUser()['username'],
31+
));
32+
}
33+
}
34+
}

Documentation/ExtensionArchitecture/HowTo/Events/_Joh316PasswordInvalidator.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)