-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly wired listeners and services
- Loading branch information
Showing
38 changed files
with
504 additions
and
698 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
53 changes: 53 additions & 0 deletions
53
src/EventListener/DataContainer/ArticleCallbackListener.php
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,53 @@ | ||
<?php | ||
|
||
namespace Hschottm\TagsBundle\EventListener\DataContainer; | ||
|
||
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; | ||
use Contao\DataContainer; | ||
use Doctrine\DBAL\Connection; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
|
||
class ArticleCallbackListener | ||
{ | ||
public function __construct( | ||
private readonly TranslatorInterface $translator, | ||
private readonly Connection $db, | ||
) | ||
{ | ||
} | ||
|
||
#[AsCallback(table: 'tl_article', target: 'config.oncopy')] | ||
public function onCopyArticle(int $insertId, DataContainer $dc): void | ||
{ | ||
if (!$dc->id) { | ||
return; | ||
} | ||
|
||
$objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table)); | ||
$tags = array(); | ||
while (($row = $objTags->fetchAssociative()) !== false) { | ||
\array_push($tags, array("table" => $dc->table, "tag" => $row['tag'])); | ||
} | ||
foreach ($tags as $entry) { | ||
$this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table'])); | ||
} | ||
} | ||
|
||
#[AsCallback(table: 'tl_article', target: 'config.ondelete')] | ||
public function onDeleteArticle(DataContainer $dc, int $undoId): void | ||
{ | ||
if (!$dc->id) { | ||
return; | ||
} | ||
|
||
$this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") | ||
->executeQuery(array($dc->table, $dc->id)); | ||
$arrContentElements = $this->db->prepare("SELECT DISTINCT id FROM tl_content WHERE pid = ?") | ||
->executeQuery(array($dc->id)); | ||
while (($row = $arrContentElements->fetchAssociative()) !== false) { | ||
$this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") | ||
->executeQuery(array('tl_content', $row['id'])); | ||
} | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
src/EventListener/DataContainer/ArticleCopyCallbackListener.php
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
src/EventListener/DataContainer/ArticleDeleteCallbackListener.php
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
src/EventListener/DataContainer/CalendarCallbackListener.php
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 | ||
|
||
namespace Hschottm\TagsBundle\EventListener\DataContainer; | ||
|
||
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; | ||
use Contao\DataContainer; | ||
use Doctrine\DBAL\Connection; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
|
||
class CalendarCallbackListener | ||
{ | ||
public function __construct( | ||
private readonly TranslatorInterface $translator, | ||
private readonly Connection $db, | ||
) | ||
{ | ||
} | ||
|
||
#[AsCallback(table: 'tl_calendar_events', target: 'config.oncopy')] | ||
public function onCopyCalendar(int $insertId, DataContainer $dc): void | ||
{ | ||
if (!$dc->id) { | ||
return; | ||
} | ||
|
||
$objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table)); | ||
$tags = array(); | ||
while (($row = $objTags->fetchAssociative()) !== false) { | ||
\array_push($tags, array("table" => $dc->table, "tag" => $row['tag'])); | ||
} | ||
foreach ($tags as $entry) { | ||
$this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table'])); | ||
} | ||
} | ||
|
||
#[AsCallback(table: 'tl_calendar_events', target: 'config.ondelete')] | ||
public function onDeleteCalendar(DataContainer $dc, int $undoId): void | ||
{ | ||
if (!$dc->id) { | ||
return; | ||
} | ||
|
||
$this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") | ||
->executeQuery(array($dc->table, $dc->id)); | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
src/EventListener/DataContainer/CalendarEventCopyCallbackListener.php
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
src/EventListener/DataContainer/CalendarEventDeleteCallbackListener.php
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
src/EventListener/DataContainer/ContentCallbackListener.php
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 | ||
|
||
namespace Hschottm\TagsBundle\EventListener\DataContainer; | ||
|
||
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; | ||
use Contao\DataContainer; | ||
use Doctrine\DBAL\Connection; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
|
||
class ContentCallbackListener | ||
{ | ||
public function __construct( | ||
private readonly TranslatorInterface $translator, | ||
private readonly Connection $db, | ||
) | ||
{ | ||
} | ||
|
||
#[AsCallback(table: 'tl_content', target: 'config.oncopy')] | ||
public function onCopyContent(int $insertId, DataContainer $dc): void | ||
{ | ||
if (!$dc->id) { | ||
return; | ||
} | ||
|
||
$objTags = $this->db->prepare("SELECT * FROM tl_tag WHERE tid = ? AND from_table = ?")->executeQuery(array($dc->id, $dc->table)); | ||
$tags = array(); | ||
while (($row = $objTags->fetchAssociative()) !== false) { | ||
\array_push($tags, array("table" => $dc->table, "tag" => $row['tag'])); | ||
} | ||
foreach ($tags as $entry) { | ||
$this->db->prepare("INSERT INTO tl_tag (tid, tag, from_table) VALUES (?, ?, ?)")->executeQuery(array($insertId, $entry['tag'], $entry['table'])); | ||
} | ||
} | ||
|
||
#[AsCallback(table: 'tl_content', target: 'config.ondelete')] | ||
public function onDeleteContent(DataContainer $dc, int $undoId): void | ||
{ | ||
if (!$dc->id) { | ||
return; | ||
} | ||
|
||
$this->db->prepare("DELETE FROM tl_tag WHERE from_table = ? AND tid = ?") | ||
->executeQuery(array($dc->table, $dc->id)); | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
src/EventListener/DataContainer/ContentCopyCallbackListener.php
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
src/EventListener/DataContainer/ContentDeleteCallbackListener.php
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.