Stand auch schon vor dem Problem. Eine Idee wäre es für die Zukunft, dass man Hooks von Anfang an so baut, dass sie deaktivierbar sind und dass es wie zum Standard wird.
In der Export Table Erweiterung bin ich diesen Weg gegangen.
https://github.com/markocupic/export...e-hook-steuern
PHP-Code:
// App/EventListener/ExportTable/FormatDateListener.php
declare(strict_types=1);
namespace App\EventListener\ExportTable;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\Date;
use Markocupic\ExportTable\Config\Config;
use Markocupic\ExportTable\Listener\ContaoHooks\ExportTableFormatDateListener;
/**
* @Hook(MyCustomFormatDateListener::HOOK, priority=MyCustomFormatDateListener::PRIORITY)
*/
class MyCustomFormatDateListener
{
public const HOOK = 'exportTable';
public const PRIORITY = 100;
public static $disableHook = false;
private $framework;
public function __construct(ContaoFramework $framework)
{
$this->framework = $framework;
}
/**
* @param $varValue
*
* @return mixed
*/
public function __invoke(string $strFieldname, $varValue, string $strTablename, array $arrDataRecord, array $arrDca, Config $objConfig)
{
if (static::$disableHook) {
return false;
}
// Disable original Hook that is shipped with the export table extension.
ExportTableFormatDateListener::$disableHook = true;
$dateAdapter = $this->framework->getAdapter(Date::class);
$dca = $arrDca['fields'][$strFieldname] ?? null;
if ($dca) {
$strRgxp = $dca['eval']['rgxp'];
if ('' !== $varValue && $strRgxp && \in_array($strRgxp, ['date', 'datim', 'time'], true)) {
$dateFormat = $dateAdapter->getFormatFromRgxp($strRgxp);
$varValue = $dateAdapter->parse($dateFormat, $varValue);
}
}
return $varValue;
}
}
Lesezeichen