Zitat von
Spooky
Ich denke du solltest eher einen save_callback für tl_news.published implementieren. Der onsubmit würde nicht ausgeführt werden, wenn man bspw. den Toggle in der Liste nutzt.
Hallo Spooky, danke für den Hinweis.
Wie genau registriere ich denn den save_callback?
Den onsubmit-Callback hatte ich über die services.yml eingebunden:
Code:
...\...Bundle\EventListener\DataContainer\OnSubmitListener:
tags:
- { name: contao.callback, table: tl_content, target: config.onsubmit, method: contentOnsubmitCallback, priority: 100 }
# - { name: contao.callback, table: tl_news, target: config.onsubmit, method: newsOnsubmitCallback, priority: 100 }
Das Beispiel in der Doku funktioniert irgendwie nicht.
Also "NewsPublishedSaveCallback.php" unter "EventListener/DataContainer" angelegt.
Und in die Datei "NewsPublishedSaveCallback.php" diesen Block kopiert:
PHP-Code:
<?php
// src/EventListener/DataContainer/ContentTextSaveCallback.php
namespace App\EventListener\DataContainer;
use Contao\CoreBundle\ServiceAnnotation\Callback;
use Contao\DataContainer;
/**
* @Callback(table="tl_news", target="fields.published.save")
*/
class NewsPublishedSaveCallback
{
public function __invoke($value, DataContainer $dc)
{
dd($value);
// Show an error if tl_content.text contains "foobar"
if (false !== stripos($value, 'foobar')) {
throw new \Exception('String "foobar" is not allowed.');
}
// Or process the value before saving
$value = strtoupper($value);
// Return the processed value
return $value;
}
}
Oder muss das über die DCA tl_news.php laufen?
PHP-Code:
$GLOBALS['TL_DCA']['tl_news']['fields']['published']['save_callback']
Wenn ja, wie genau mache ich das dann?
Lesezeichen