Skip to content

Commit

Permalink
Merge branch 'feature/improvements' into 'main'
Browse files Browse the repository at this point in the history
add form label listener

See merge request trilobit/trilobit-gmbh/bundles/contao-aceid-bundle!11
  • Loading branch information
trilobit-gmbh committed Mar 15, 2024
2 parents 36eb0e9 + ab2f040 commit 11e291d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/EventListener/FormLabelCallbackListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/*
* @copyright trilobit GmbH
* @author trilobit GmbH <https://github.com/trilobit-gmbh>
* @license LGPL-3.0-or-later
*/

namespace Trilobit\AceidBundle\EventListener;

use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\ServiceAnnotation\Callback;
use Contao\Database;
use Contao\DataContainer;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* @Callback(table="tl_form", target="list.label.label")
*/
class FormLabelCallbackListener
{
private $translator;
private $framework;

public function __construct(ContaoFramework $framework, TranslatorInterface $translator)
{
$this->framework = $framework;
$this->translator = $translator;
}

public function __invoke(array $row, string $label, DataContainer $dc, array $labels): string
{
return $label
.'<span style="color:#A3A3A3;margin-left:3px;padding-left:3px">[ID: '.$row['id'].' / '.$this->translator->trans('MSC.filterRecords', [], 'contao_default').': '.self::getChildRecordsCount($row['id']).']</span>';
}

protected static function getChildRecordsCount($pid): string
{
return (string) Database::getInstance()
->prepare('SELECT count(id) AS count FROM tl_form_field WHERE pid=?')
->execute($pid)
->count;
}
}

0 comments on commit 11e291d

Please sign in to comment.