Habe jetzt versucht auf die "neue" Art umzusetzen:
PHP-Code:
<?php
// src/EventListener/DataContainer/myCallbackListener.php
namespace App\EventListener\DataContainer;
use Contao\CoreBundle\ServiceAnnotation\Callback;
use Contao\DataContainer;
class myCallbackListener
{
/**
* @Callback(table="tl_content", target="field.myDemoData.save")
*/
public function myTest($myValue, DataContainer $dc): string
{
// Do something …
dump($dc);
return 'Hooray';
}
}
PHP-Code:
<?php
// contao/dca/tl_content.php
use Contao\CoreBundle\DataContainer\PaletteManipulator;
$GLOBALS['TL_DCA']['tl_content']['fields']['myDemoData'] = [
'label' => ['Mein Element', 'Meine Beschreibung'],
'inputType' => 'text',
'explanation' => 'my_explanation',
'eval' => ['tl_class' => 'w50', 'helpwizard' => true],
'sql' => 'text NULL',
// Working
'save_callback' => [
[App\EventListener\DataContainer\myCallbackListener::class, 'myTest']
],
];
PaletteManipulator::create()
->addLegend('Einstellungen Demo', 'type_legend', PaletteManipulator::POSITION_AFTER)
->addField('myDemoData', 'Einstellungen Demo', PaletteManipulator::POSITION_APPEND)
->applyToPalette('text', 'tl_content')
;
Der CM sollte doch dann das "src" Verzeichnis erkennen und entsprechend die composer.json erweitern?
Macht er nicht - Wie ist die Vorgehensweise?
Hab dann die composer.json manuell geändert ala:
HTML-Code:
{
"type": "project",
"require": {
"contao/calendar-bundle": "4.10.*",
"contao/comments-bundle": "4.10.*",
"contao/conflicts": "*@dev",
"contao/faq-bundle": "4.10.*",
"contao/listing-bundle": "4.10.*",
"contao/manager-bundle": "4.10.*",
"contao/news-bundle": "4.10.*",
"contao/newsletter-bundle": "4.10.*",
"erdmannfreunde/euf_grid": "^3.1"
},
"extra": {
"contao-component-dir": "assets"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"scripts": {
"post-install-cmd": [
"Contao\\ManagerBundle\\Composer\\ScriptHandler::initializeApplication"
],
"post-update-cmd": [
"Contao\\ManagerBundle\\Composer\\ScriptHandler::initializeApplication"
]
}
}
und dann auf der Console mit:
HTML-Code:
composer install
composer dump-autoload
Der Test via:
Code:
vendor/bin/contao-console debug:container App\EventListener\DataContainer\myCallbackListener
ergibt dannn:
Code:
Option Value
---------------- ------------------------------------------------------------------------------------
Service ID App\EventListener\DataContainer\myCallbackListener
Class App\EventListener\DataContainer\myCallbackListener
Tags contao.callback (table: tl_content, target: field.myDemoData.save, method: myTest)
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired yes
Autoconfigured yes
... und es funktioniert dann ...
Wie bringe ich dann den CM dazu die composer.json um den autoload Eintrag zu erweitern?
Lesezeichen