Skip to content

Commit

Permalink
Use attributes instead of service annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolineus committed Feb 28, 2024
1 parent 8f7dabb commit c65f456
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
19 changes: 7 additions & 12 deletions src/EventListener/Dca/Page/RootInheritListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Hofff\Contao\TrueUrl\EventListener\Dca\Page;

use Contao\CoreBundle\ServiceAnnotation\Callback;
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
use Contao\DataContainer;
use Contao\PageModel;
use Doctrine\DBAL\Connection;
Expand All @@ -20,11 +20,8 @@ public function __construct(private readonly Connection $connection)
{
}

/**
* @param array<string,mixed> $set
*
* @Callback(table="tl_page", target="config.oncreate", priority=128)
*/
/** @param array<string,mixed> $set */
#[AsCallback('tl_page', 'config.oncreate', priority:128)]
public function onCreate(string $table, string|int $recordId, array $set): void
{
if (! $set['pid']) {
Expand Down Expand Up @@ -54,10 +51,8 @@ public function onCreate(string $table, string|int $recordId, array $set): void
);
}

/**
* @Callback(table="tl_page", target="fields.bbit_turl_rootInheritProxy.load")
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
/** @SuppressWarnings(PHPMD.UnusedFormalParameter) */
#[AsCallback('tl_page', 'fields.bbit_turl_rootInheritProxy.load')]
public function onLoad(mixed $varValue, DataContainer $dataContainer): mixed
{
if (! $dataContainer->activeRecord) {
Expand All @@ -67,7 +62,7 @@ public function onLoad(mixed $varValue, DataContainer $dataContainer): mixed
return $dataContainer->activeRecord->bbit_turl_rootInherit ?: 'normal';
}

/** @Callback(table="tl_page", target="fields.bbit_turl_rootInheritProxy.save") */
#[AsCallback('tl_page', 'fields.bbit_turl_rootInheritProxy.save')]
public function onSave(mixed $newValue, DataContainer $dataContainer): mixed
{
if (! $dataContainer->activeRecord) {
Expand All @@ -83,7 +78,7 @@ public function onSave(mixed $newValue, DataContainer $dataContainer): mixed
return null;
}

/** @Callback(table="tl_page", target="config.onsubmit", priority=-1) */
#[AsCallback('tl_page', 'config.onsubmit', priority: -1)]
public function onSubmit(DataContainer $dataContainer): void
{
if (! isset($this->changedValues[$dataContainer->id]) || ! $dataContainer->activeRecord) {
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/Hook/CustomRegularExpressionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Hofff\Contao\TrueUrl\EventListener\Hook;

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\Widget;
use Symfony\Contracts\Translation\TranslatorInterface;

use function preg_match;

/** @Hook("addCustomRegexp") */
#[AsHook('addCustomRegexp')]
final class CustomRegularExpressionListener
{
public function __construct(private readonly TranslatorInterface $translator)
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/Hook/LoadDataContainerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Hofff\Contao\TrueUrl\EventListener\Hook;

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Hofff\Contao\TrueUrl\EventListener\Dca\Page\GenerateLabelListener;

/** @Hook("loadDataContainer") */
#[AsHook('loadDataContainer')]
final class LoadDataContainerListener
{
/** @SuppressWarnings(PHPMD.Superglobals) */
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/Hook/PageDetailsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Hofff\Contao\TrueUrl\EventListener\Hook;

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\PageModel;
use Hofff\Contao\TrueUrl\TrueURL;

/** @Hook("loadPageDetails") */
#[AsHook('loadPageDetails')]
final class PageDetailsListener
{
public function __construct(private readonly TrueURL $trueUrl)
Expand Down

0 comments on commit c65f456

Please sign in to comment.