Ergebnis 1 bis 15 von 15

Thema: Header fields werden in der childTabelle nicht angezeigt

  1. #1
    Contao-Nutzer
    Registriert seit
    18.12.2010.
    Ort
    Mühltal
    Beiträge
    55

    Standard Header fields werden in der childTabelle nicht angezeigt

    Hallo Community,

    ich bin am verzweifeln und finde den Fehler nicht. Die parent-Tabelle ist tl_dc_regulators und die Child-Tabelle tl_dc_regulator-control.
    Die headerFields werden nicht angezeigt, wenn die Kindtabelle angeklickt wird. Ich kann die Parent Tabelle vom Kinddatensatz aus bearbeiten, also sind die Tabellen korrekt verknüpft. In Symfony wird angezeigt: "No parent ID found for record in tl_dc_regulator_control."
    Es gibt aber einen entsprechenden Datensatz.

    Was übersehe ich? Hat jemand eine Idee?

    Danke schon jetzt für Eure Hilfe!

    tl_dc_regulators

    Code:
    <?php
    
    declare(strict_types=1);
    
    /**
     * This file is part of ContaoDiveclubBundle.
     *
     * (c) DiversWorld, Eckhard Becker 2025 <info@diversworld.eu>
     * @license GPL-3.0-or-later
     * For the full copyright and license information,
     * please view the LICENSE file that was distributed with this source code.
     * @link https://github.com/diversworld/contao-diveclub-bundle
     */
    
    use Contao\Backend;
    use Contao\Database;
    use Contao\DataContainer;
    use Contao\DC_Table;
    use Contao\System;
    use Psr\Log\LoggerInterface;
    use Contao\TemplateLoader;
    
    /**
     * Table tl_dc_regulators
     */
    $GLOBALS['TL_DCA']['tl_dc_regulators'] = [
        'config'            => [
            'dataContainer'     => DC_Table::class,
            'ctable'            => ['tl_dc_regulator_control'],
            'enableVersioning'  => true,
            'sql'               => [
                'keys'              => [
                    'id'                => 'primary',
                    'tstamp'            => 'index',
                    'alias'             => 'index',
                    'published,start,stop' => 'index'
                ]
            ],
        ],
        'list'              => [
            'sorting'           => [
                'mode'              => DataContainer::MODE_SORTABLE,
                'fields'            => ['title','alias','published'],
                'flag'              => DataContainer::SORT_ASC,
                'panelLayout'       => 'filter;sort,search,limit'
            ],
            'label'             => [
                'fields'            => ['title','manufacturer','regModel1st','regModel2ndPri','regModel2ndSec'],
                'format'            => '%s %s %s %s %s',
                'showColumns'       => true,
                'label_callback'    => ['tl_dc_regulators', 'customLabelCallback']
            ],
            'global_operations' => [
                'all'               => [
                    'href'          => 'act=select',
                    'class'         => 'header_edit_all',
                    'attributes'    => 'onclick="Backend.getScrollOffset()" accesskey="e"'
                ]
            ],
            'operations'        => [
                'edit',
                'children',
                'copy',
                'delete',
                'toggle',
                'show',
            ],
        ],
        'palettes'          => [
            '__selector__'      => ['addNotes'],
            'default'           => '{title_legend},title,alias;
                                    {1stStage_legend},manufacturer,serialNumber1st,regModel1st;
                                    {2ndstage_legend},serialNumber2ndPri,regModel2ndPri,serialNumber2ndSec,regModel2ndSec;
                                    {notes_legend},addNotes;
                                    {publish_legend},published,start,stop;'
        ],
        'subpalettes'       => [
            'addNotes'          => 'notes',
        ],
        'fields'            => [
            'id'                => [
                'sql'               => "int(10) unsigned NOT NULL auto_increment"
            ],
            'tstamp'            => [
                'sql'               => "int(10) unsigned NOT NULL default 0"
            ],
            'title'             => [
                'inputType'         => 'text',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['title'],
                'search'            => true,
                'filter'            => true,
                'sorting'           => true,
                'flag'              => DataContainer::SORT_ASC,
                'eval'              => ['mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w33'],
                'sql'               => "varchar(255) NOT NULL default ''"
            ],
            'alias'             => [
                'search'            => true,
                'inputType'         => 'text',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['alias'],
                'eval'              => ['rgxp'=>'alias', 'doNotCopy'=>true, 'unique'=>true, 'maxlength'=>255, 'tl_class'=>'w33'],
                'save_callback'     => [
                    ['tl_dc_regulators', 'generateAlias']
                ],
                'sql'           => "varchar(255) BINARY NOT NULL default ''"
            ],
            'manufacturer'      => [
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['manufacturer'],
                'inputType'         => 'select',
                'search'            => true,
                'filter'            => true,
                'sorting'           => true,
                'options_callback'  => array('tl_dc_regulators', 'getManufacturers'),
                'eval'              => array('includeBlankOption' => true, 'submitOnChange' => true, 'mandatory' => true, 'tl_class' => 'w25 clr'),
                'sql'               => "varchar(255) NOT NULL default ''",
            ],
            'serialNumber1st'   => [
                'inputType'         => 'text',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['serialNumber1st'],
                'search'            => true,
                'filter'            => true,
                'sorting'           => true,
                'flag'              => DataContainer::SORT_INITIAL_LETTER_ASC,
                'eval'              => ['mandatory' => true, 'maxlength' => 50, 'tl_class' => 'w25'],
                'sql'               => "varchar(50) NOT NULL default ''"
            ],
            'regModel1st'       => [
                'inputType'         => 'select',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['regModel1st'],
                'exclude'           => true,
                'search'            => true,
                'filter'            => true,
                'sorting'           => true,
                'options_callback'  => ['tl_dc_regulators', 'getRegModels1st'],
                'eval'              => ['includeBlankOption' => true, 'mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w25'],
                'sql'               => "varchar(255) NOT NULL default ''"
            ],
            'serialNumber2ndPri'=> [
                'inputType'         => 'text',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['serialNumber2ndPri'],
                'search'            => true,
                'filter'            => true,
                'sorting'           => true,
                'flag'              => DataContainer::SORT_INITIAL_LETTER_ASC,
                'eval'              => ['mandatory' => false, 'maxlength' => 50, 'tl_class' => 'w25 clr'],
                'sql'               => "varchar(50) NOT NULL default ''"
            ],
            'regModel2ndPri'    => [
                'inputType'         => 'select',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['regModel2ndPri'],
                'exclude'           => true,
                'search'            => true,
                'filter'            => true,
                'sorting'           => true,
                'options_callback'  => ['tl_dc_regulators', 'getRegModels2nd'],
                'eval'              => ['includeBlankOption' => true, 'submitOnChange' => true, 'mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w25'],
                'sql'               => "varchar(255) NOT NULL default ''"
            ],
            'serialNumber2ndSec'=> [
                'inputType'         => 'text',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['serialNumber2ndSec'],
                'search'            => true,
                'filter'            => true,
                'sorting'           => true,
                'eval'              => ['mandatory' => false, 'maxlength' => 50, 'tl_class' => 'w25'],
                'sql'               => "varchar(50) NOT NULL default ''"
            ],
            'regModel2ndSec'    => [
                'inputType'         => 'select',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['regModel2ndSec'],
                'exclude'           => true,
                'search'            => true,
                'filter'            => true,
                'sorting'           => true,
                'options_callback'  => ['tl_dc_regulators', 'getRegModels2nd'],
                'eval'              => ['includeBlankOption' => true,'submitOnChange' => true, 'mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w25'],
                'sql'               => "varchar(255) NOT NULL default ''"
            ],
            'addNotes'          => [
                'inputType'         => 'checkbox',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['addNotes'],
                'exclude'           => true,
                'eval'              => ['submitOnChange' => true, 'tl_class' => 'w50'],
                'sql'               => ['type' => 'boolean', 'default' => false]
            ],
            'notes'             => [
                'inputType'         => 'textarea',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['notes'],
                'exclude'           => true,
                'search'            => false,
                'filter'            => false,
                'sorting'           => false,
                'eval'              => ['rte' => 'tinyMCE', 'tl_class' => 'clr'],
                'sql'               => 'text NULL'
            ],
            'published'         => [
                'inputType'         => 'checkbox',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['published'],
                'toggle'            => true,
                'filter'            => true,
                'flag'              => DataContainer::SORT_INITIAL_LETTER_DESC,
                'eval'              => ['doNotCopy'=>true, 'tl_class' => 'w50'],
                'sql'               => ['type' => 'boolean', 'default' => false]
            ],
            'start'             => [
                'inputType'         => 'text',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['start'],
                'eval'              => ['rgxp'=>'datim', 'datepicker'=>true, 'tl_class'=>'w50 clr wizard'],
                'sql'               => "varchar(10) NOT NULL default ''"
            ],
            'stop'              => [
                'inputType'         => 'text',
                'label'             => &$GLOBALS['TL_LANG']['tl_dc_regulators']['stop'],
                'eval'              => ['rgxp'=>'datim', 'datepicker'=>true, 'tl_class'=>'w50 wizard'],
                'sql'               => "varchar(10) NOT NULL default ''"
            ]
        ]
    ];
    
    class tl_dc_regulators extends Backend
    {
        public LoggerInterface $logger;
    
        /**
         * Auto-generate the event alias if it has not been set yet
         *
         * @param mixed $varValue
         * @param DataContainer $dc
         *
         * @return mixed
         *
         * @throws Exception
         */
        public function generateAlias(mixed $varValue, DataContainer $dc): mixed
        {
            $aliasExists = static function (string $alias) use ($dc): bool {
                $result = Database::getInstance()
                    ->prepare("SELECT id FROM tl_dc_regulators WHERE alias=? AND id!=?")
                    ->execute($alias, $dc->id);
                return $result->numRows > 0;
            };
    
            // Generate the alias if there is none
            if (!$varValue) {
                $varValue = System::getContainer()->get('contao.slug')->generate(
                    $dc->activeRecord->title,
                    [],
                    $aliasExists
                );
            } elseif (preg_match('/^[1-9]\d*$/', $varValue)) {
                throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasNumeric'], $varValue));
            } elseif ($aliasExists($varValue)) {
                throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
            }
    
            return $varValue;
        }
        public function getManufacturers()
        {
            return $this->getTemplateOptions('equipment_manufacturers');
        }
    
        public function getSizes()
        {
            return $this->getTemplateOptions('equipment_sizes');
        }
    
        private function getTemplateOptions($templateName)
        {
            // Templatepfad über Contao ermitteln
            $templatePath = TemplateLoader::getPath($templateName, 'html5');
    
            // Überprüfen, ob die Datei existiert
            if (!$templatePath || !file_exists($templatePath)) {
                throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['templateNotFound'], $templatePath));
            }
    
            //$options = include $templatePath;
    
            // Dateiinhalt lesen
            $content = file_get_contents($templatePath);
    
            $options = [];
            // Entferne PHP-Tags und wandle Daten in ein Array um
            $content = trim($content);
            $content = trim($content, '<?=');
            $content = trim($content, '?>');
    
            eval('$options = ' . $content . ';');
    
            if (!is_array($options)) {
                throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['templateContent'], $content));
            }
    
            return $options;
        }
        public function getRegModels1st(DataContainer $dc): array
        {
            // Sicherstellen, dass ein aktiver Datensatz vorhanden ist
            if (!$dc->activeRecord || !$dc->activeRecord->manufacturer) {
                return [];
            }
    
            // Ermittle den aktuellen Typ aus dem aktiven Datensatz
            $manufacturer = $dc->activeRecord->manufacturer; // Aktueller Hersteller
            $models = $this->getTemplateOptions('regulator_data');
    
            // Prüfen, ob der Hersteller existiert und Modelle für die erste Stufe definiert sind
            if (!isset($models[$manufacturer]['regModel1st']) || !is_array($models[$manufacturer]['regModel1st'])) {
                return [];
            }
    
            // Rückgabe der Modelle für die erste Stufe
            return $models[$manufacturer]['regModel1st'];
        }
    
        public function getRegModels2nd(DataContainer $dc): array
        {
            if (!$dc->activeRecord || !$dc->activeRecord->manufacturer) {
                return [];
            }
    
            $manufacturer = $dc->activeRecord->manufacturer; // Aktueller Hersteller
            $models = $this->getTemplateOptions('regulator_data');
    
            // Prüfen, ob der Hersteller existiert und Modelle für die zweite Stufe definiert sind
            if (!isset($models[$manufacturer]['regModel2nd']) || !is_array($models[$manufacturer]['regModel2nd'])) {
                return [];
            }
    
            // Rückgabe der Modelle für die zweite Stufe
            return $models[$manufacturer]['regModel2nd'];
        }
    
        public function customLabelCallback(array $row, string $label, DataContainer $dc = null, array $args = null): array
        {
            // Hersteller auslesen
            $manufacturer = $row['manufacturer'];
            $manufacturers = $this->getManufacturers();
    
            $args[1] = $manufacturers[$row['manufacturer']] ?? '-'; // Hersteller-Name einsetzen
    
            // Modelle für die erste und zweite Stufe basierend auf dem Hersteller laden
            $models = $this->getTemplateOptions('regulator_data');
    
            // Namen der Modelle statt der Indexwerte benutzen
            if (isset($models[$manufacturer]['regModel1st'][$row['regModel1st']])) {
                $args[2] = $models[$manufacturer]['regModel1st'][$row['regModel1st']];
            } else {
                $args[2] = '-'; // Fallback, falls nichts gefunden wird
            }
    
            if (isset($models[$manufacturer]['regModel2nd'][$row['regModel2ndPri']])) {
                $args[3] = $models[$manufacturer]['regModel2nd'][$row['regModel2ndPri']];
            } else {
                $args[3] = '-'; // Fallback
            }
    
            if (isset($models[$manufacturer]['regModel2nd'][$row['regModel2ndSec']])) {
                $args[4] = $models[$manufacturer]['regModel2nd'][$row['regModel2ndSec']];
            } else {
                $args[4] = '-'; // Fallback
            }
    
            return $args;
        }
    
    }
    tl_dc_regulator_control
    Code:
    <?php
    
    declare(strict_types=1);
    
    /*
     * This file is part of ContaoDiveclubBundle.
     *
     * (c) Diversworld, Eckhard Becker 2025 <info@diversworld.eu>
     * @license GPL-3.0-or-later
     * For the full copyright and license information,
     * please view the LICENSE file that was distributed with this source code.
     * @link https://github.com/diversworld/contao-diveclub-bundle
     */
    
    use Contao\Backend;
    use Contao\Database;
    use Contao\DataContainer;
    use Contao\DC_Table;
    use Contao\System;
    use Psr\Log\LoggerInterface;
    use Contao\TemplateLoader;
    
    /**
     * Table tl_dc_regulator_control
     */
    $GLOBALS['TL_DCA']['tl_dc_regulator_control'] = [
        'config'        => [
            'dataContainer'     => DC_Table::class,
            'ptable'            => 'tl_dc_regulators',
            'enableVersioning'  => true,
            'onload_callback' => [
                ['tl_dc_regulator_control', 'debugParentData'],
            ],
    
            'sql'               => [
                'keys'          => [
                    'id'            => 'primary',
                    'pid'           => 'index',
                    'tstamp'        => 'index',
                    'alias'         => 'index',
                    'published,start,stop' => 'index'
                ]
            ],
        ],
        'list'                  => [
            'sorting'               => [
                'mode'                  => DataContainer::MODE_PARENT,
                'fields'                => ['title','nextCheckDate','alias','published'],
                'headerFields'          => ['title','manufacturer','regModel1st','serialNumber1st','regModel2ndPri','serialNumber2ndPri','regModel2ndSec','serialNumber2ndSec'],// Felder aus der Eltern-Tabelle
                'flag'                  => DataContainer::SORT_ASC,
                'panelLayout'           => 'filter;sort,search,limit'
            ],
            'label'                 => [
                'fields'                => ['title','midPressurePre','inhalePressurePre','exhalePressurePre','midPressurePost','inhalePressurePost','exhalePressurePost'],
                'format'                => '%s: Vorher MD %s bar EAW %s AAW %s - Nachher MD %s bar EAW %s AAW %s',
            ],
            'global_operations'     => [
                'all'                   => [
                    'href'                  => 'act=select',
                    'class'                 => 'header_edit_all',
                    'attributes'            => 'onclick="Backend.getScrollOffset()" accesskey="e"'
                ]
            ],
            'operations'            => [
                'edit',
                'copy',
                'delete',
                'toggle',
                'show',
            ],
        ],
        'palettes'              => [
            '__selector__'      => ['addNotes'],
            'default'           => '{title_legend},title,alias;
                                    {pre_legend},midPreussurePre,inhalePressurePre,exhalePressurePre;
                                    {post_legend},midPreussurePost,inhalePressurePost,exhalePressurePost;
                                    {nextCheck_legend},nextCheckDate;
                                    {notes_legend},addNotes;
                                    {publish_legend},published,start,stop;'
        ],
        'subpalettes'           => [
            'addNotes'          => 'notes',
        ],
        'fields'                => [
            'id'                    => [
                'sql'                   => "int(10) unsigned NOT NULL auto_increment"
            ],
            'pid'                   => [
                'foreignKey'            => 'tl_dc_regulators.title',
                'relation'              => ['type' => 'belongsTo', 'load' => 'lazy'], // Typ anpassen, falls notwendig
                'sql'                   => "int(10) unsigned NOT NULL default 0",
            ],
            'tstamp'                => [
                'sql'                   => "int(10) unsigned NOT NULL default 0"
            ],
            'title'                 => [
                'inputType'             => 'text',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['actualCheckDate'],
                'exclude'               => true,
                'search'                => true,
                'filter'                => true,
                'sorting'               => true,
                'flag'                  => DataContainer::SORT_YEAR_DESC,
                'eval'                  => ['submitOnChange' => true, 'rgxp'=>'date', 'mandatory'=>false, 'doNotCopy'=>true, 'datepicker'=>true, 'tl_class'=>'w33 wizard'],
                'sql'                   => "varchar(10) NOT NULL default ''"
            ],
            'alias'                 => [
                'search'                => true,
                'inputType'             => 'text',
                'eval'                  => ['rgxp'=>'alias', 'doNotCopy'=>true, 'unique'=>true, 'maxlength'=>255, 'tl_class'=>'w50'],
                'save_callback'         => [
                    ['tl_dc_regulator_control', 'generateAlias']
                ],
                'sql'           => "varchar(255) BINARY NOT NULL default ''"
            ],
            'midPressurePre'        => [
                'inputType'             => 'text',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['midPreussurePre'],
                'search'                => true,
                'filter'                => true,
                'sorting'               => true,
                'eval'                  => ['mandatory' => true, 'maxlength' => 50, 'tl_class' => 'w25 clr'],
                'sql'                   => "varchar(50) NOT NULL default ''"
            ],
            'inhalePressurePre'     => [
                'inputType'             => 'text',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['inhalePressurePre'],
                'search'                => true,
                'filter'                => true,
                'sorting'               => true,
                'eval'                  => ['mandatory' => true, 'maxlength' => 50, 'tl_class' => 'w25'],
                'sql'                   => "varchar(50) NOT NULL default ''"
            ],
            'exhalePressurePre'     => [
                'inputType'             => 'text',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['exhalePressurePre'],
                'search'                => true,
                'filter'                => true,
                'sorting'               => true,
                'eval'                  => ['mandatory' => true, 'maxlength' => 50, 'tl_class' => 'w25'],
                'sql'                   => "varchar(50) NOT NULL default ''"
            ],
            'midPressurePost'       => [
                'inputType'             => 'text',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['midPreussurePost'],
                'search'                => true,
                'filter'                => true,
                'sorting'               => true,
                'eval'                  => ['mandatory' => true, 'maxlength' => 50, 'tl_class' => 'w25 clr'],
                'sql'                   => "varchar(50) NOT NULL default ''"
            ],
            'inhalePressurePost'    => [
                'inputType'             => 'text',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['inhalePressurePost'],
                'search'                => true,
                'filter'                => true,
                'sorting'               => true,
                'flag'                  => DataContainer::SORT_INITIAL_LETTER_ASC,
                'eval'                  => ['mandatory' => true, 'maxlength' => 50, 'tl_class' => 'w25'],
                'sql'                   => "varchar(50) NOT NULL default ''"
            ],
            'exhalePressurePost'    => [
                'inputType'             => 'text',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['exhalePressurePost'],
                'search'                => true,
                'filter'                => true,
                'sorting'               => true,
                'flag'                  => DataContainer::SORT_INITIAL_LETTER_ASC,
                'eval'                  => ['mandatory' => true, 'maxlength' => 50, 'tl_class' => 'w25'],
                'sql'                   => "varchar(50) NOT NULL default ''"
            ],
            'nextCheckDate'         => [
                'inputType'             => 'text',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['nextCheckDate'],
                'sorting'               => true,
                'filter'                => true,
                'flag'                  => DataContainer::SORT_YEAR_DESC,
                'eval'                  => ['submitOnChange' => true,'rgxp'=>'date', 'doNotCopy'=>false, 'datepicker'=>true, 'tl_class'=>'w33 wizard'],
                'sql'                   => "varchar(10) NOT NULL default ''"
            ],
            'addNotes'              => [
                'inputType'             => 'checkbox',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['addNotes'],
                'exclude'               => true,
                'eval'                  => ['submitOnChange' => true, 'tl_class' => 'w50'],
                'sql'                   => ['type' => 'boolean', 'default' => false]
            ],
            'notes'                 => [
                'inputType'             => 'textarea',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['notes'],
                'exclude'               => true,
                'search'                => false,
                'filter'                => false,
                'sorting'               => false,
                'eval'                  => ['rte' => 'tinyMCE', 'tl_class' => 'clr'],
                'sql'                   => 'text NULL'
            ],
            'published'             => [
                'inputType'             => 'checkbox',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['published'],
                'toggle'                => true,
                'filter'                => true,
                'flag'                  => DataContainer::SORT_INITIAL_LETTER_DESC,
                'eval'                  => ['doNotCopy'=>true, 'tl_class' => 'w50'],
                'sql'                   => ['type' => 'boolean', 'default' => false]
            ],
            'start'                 => [
                'inputType'             => 'text',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['start'],
                'eval'                  => ['rgxp'=>'datim', 'datepicker'=>true, 'tl_class'=>'w50 clr wizard'],
                'sql'                   => "varchar(10) NOT NULL default ''"
            ],
            'stop'                  => [
                'inputType'             => 'text',
                'label'                 => &$GLOBALS['TL_LANG']['tl_dc_regulator_control']['stop'],
                'eval'                  => ['rgxp'=>'datim', 'datepicker'=>true, 'tl_class'=>'w50 wizard'],
                'sql'                   => "varchar(10) NOT NULL default ''"
            ]
        ]
    ];
    
    class tl_dc_regulator_control extends Backend
    {
        public LoggerInterface $logger;
    
        /**
         * Auto-generate the event alias if it has not been set yet
         *
         * @param mixed $varValue
         * @param DataContainer $dc
         *
         * @return mixed
         *
         * @throws Exception
         */
        public function generateAlias(mixed $varValue, DataContainer $dc): mixed
        {
            $aliasExists = static function (string $alias) use ($dc): bool {
                $result = Database::getInstance()
                    ->prepare("SELECT id FROM tl_dc_regulator_control WHERE alias=? AND id!=?")
                    ->execute($alias, $dc->id);
                return $result->numRows > 0;
            };
    
            // Generate the alias if there is none
            if (!$varValue) {
                $varValue = System::getContainer()->get('contao.slug')->generate(
                    $dc->activeRecord->title,
                    [],
                    $aliasExists
                );
            } elseif (preg_match('/^[1-9]\d*$/', $varValue)) {
                throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasNumeric'], $varValue));
            } elseif ($aliasExists($varValue)) {
                throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
            }
    
            return $varValue;
        }
        public function getManufacturers()
        {
            return $this->getTemplateOptions('equipment_manufacturers');
        }
    
        public function getSizes()
        {
            return $this->getTemplateOptions('equipment_sizes');
        }
    
        private function getTemplateOptions($templateName)
        {
            // Templatepfad über Contao ermitteln
            $templatePath = TemplateLoader::getPath($templateName, 'html5');
    
            // Überprüfen, ob die Datei existiert
            if (!$templatePath || !file_exists($templatePath)) {
                throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['templateNotFound'], $templatePath));
            }
    
            // Dateiinhalt lesen
            $content = file_get_contents($templatePath);
    
            $options = [];
            // Entferne PHP-Tags und wandle Daten in ein Array um
            $content = trim($content);
            $content = trim($content, '<?=');
            $content = trim($content, '?>');
    
            eval('$options = ' . $content . ';');
    
            if (!is_array($options)) {
                $this->logger->error('Failed to parse template content into an array: ' . $content);
                return [];
            }
    
            return $options;
        }
    
        public function debugParentData(DataContainer $dc): void
        {
            $this->logger = System::getContainer()->get('monolog.logger.contao.general');
            // Lade Parent-Datensatz
            $parent = Database::getInstance()
                ->prepare("SELECT * FROM tl_dc_regulators WHERE id=?")
                ->execute($dc->id);
    
            if ($parent->numRows === 0) {
                $this->logger->error('No parent record found for ID: ' . $dc->id);
            } else {
                $this->logger->info('Parent record found: ' . print_r($parent->row(), true));
            }
        }
    
    }
    IMG_0176.png
    Geändert von diversworld (22.02.2025 um 17:13 Uhr)

  2. #2
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    37.162
    Partner-ID
    10107

    Standard

    Poste mal Screenshots.
    » sponsor me via GitHub or Revolut

  3. #3
    Contao-Nutzer
    Registriert seit
    18.12.2010.
    Ort
    Mühltal
    Beiträge
    55

    Standard

    Zitat Zitat von Spooky Beitrag anzeigen
    Poste mal Screenshots.
    Das Bild ist angehängt und auch nochmal hier:
    IMG_0176.png

  4. #4
    Alter Contao-Hase
    Registriert seit
    24.02.2021.
    Beiträge
    1.477
    Partner-ID
    11715
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Welche Contao Version ist das? Ich hab eben die DCAs mal in eine Testinstanz (Contao 5.3) geworfen und habe die Header fields

    Migrationen hast du auch laufen lassen?

  5. #5
    Contao-Fan Avatar von lbableck
    Registriert seit
    10.06.2021.
    Beiträge
    337
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Zitat Zitat von diversworld Beitrag anzeigen
    Code:
            $parent = Database::getInstance()
                ->prepare("SELECT * FROM tl_dc_regulators WHERE id=?")
                ->execute($dc->id);
    Da müsstest du ja die PID, nicht die ID des Datensatzes verwenden.
    Bzgl. den headerFields, vielleicht einfach nur den Cache vergessen zu leeren? Versuchs mal im Debug-Mode.

  6. #6
    Community-Moderator
    Wandelndes Contao-Lexikon
    Avatar von Spooky
    Registriert seit
    12.04.2012.
    Ort
    Scotland
    Beiträge
    37.162
    Partner-ID
    10107

    Standard

    Da scheint es einige Anpassungen zu geben - woher kommt dieser "staging" Hinweis bspw.?
    » sponsor me via GitHub or Revolut

  7. #7
    Contao-Nutzer
    Registriert seit
    18.12.2010.
    Ort
    Mühltal
    Beiträge
    55

    Standard

    Zitat Zitat von zoglo Beitrag anzeigen
    Welche Contao Version ist das? Ich hab eben die DCAs mal in eine Testinstanz (Contao 5.3) geworfen und habe die Header fields

    Migrationen hast du auch laufen lassen?
    Das ist die Contao Version 5.3
    Den Cache habe ich mehrfach gelöscht und contao Update, etc.
    Die dB ist auch aktuell

    - - - Aktualisiert - - -

    Zitat Zitat von Spooky Beitrag anzeigen
    Da scheint es einige Anpassungen zu geben - woher kommt dieser "staging" Hinweis bspw.?
    Ach so, der staging Hinweis im backend. Das ist das markocupic/contao-staging-installation-banner.
    Geändert von diversworld (22.02.2025 um 19:14 Uhr)

  8. #8
    Contao-Nutzer
    Registriert seit
    18.12.2010.
    Ort
    Mühltal
    Beiträge
    55

    Standard

    Zitat Zitat von Spooky Beitrag anzeigen
    Da scheint es einige Anpassungen zu geben - woher kommt dieser "staging" Hinweis bspw.?
    Ach so, der staging Hinweis im backend. Das ist das markocupic/contao-staging-installation-banner.

  9. #9
    Alter Contao-Hase
    Registriert seit
    24.02.2021.
    Beiträge
    1.477
    Partner-ID
    11715
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Wie bereits erwähnt, konnte ich das Verhalten in einer Contao 5.3 Installation nicht nachvollziehen.
    Versuche es mal in einer Blanko-Installation ohne jegliche Erweiterungen und nur mit deinen geposteten DCA.

    Vermutlich ist da noch was anderes im Argen.

  10. #10
    Contao-Nutzer
    Registriert seit
    18.12.2010.
    Ort
    Mühltal
    Beiträge
    55

    Standard

    Zitat Zitat von zoglo Beitrag anzeigen
    Wie bereits erwähnt, konnte ich das Verhalten in einer Contao 5.3 Installation nicht nachvollziehen.
    Versuche es mal in einer Blanko-Installation ohne jegliche Erweiterungen und nur mit deinen geposteten DCA.

    Vermutlich ist da noch was anderes im Argen.
    Danke, ich setze morgen eine neue Umgebung auf.

    Interessant ist aber, dass es bei den anderen Tabellen problemlos funktioniert. Nur bei diesen beiden nicht.

  11. #11
    Contao-Nutzer
    Registriert seit
    18.12.2010.
    Ort
    Mühltal
    Beiträge
    55

    Standard

    Ich verstehe es nicht.
    Jetzt geht es. Was habe ich gemacht.
    Beide Dateien umbenannt und den Code entsprechend angepasst. Jetzt geht es.
    Warum, keine Ahnung.

  12. #12
    Contao-Nutzer
    Registriert seit
    18.12.2010.
    Ort
    Mühltal
    Beiträge
    55

    Gesicht zeigt die Zunge

    Also echt mysteriös. Ich habe jetzt die Tabellennamen geändert und alles neu installiert. Auch in anderen Testinstallationen. Nirgendwo funktioniert es.
    Gestern Abend hatte ich es über mein iPad bei einer installation in den Dateien geändert und da ging es dann.
    Wenn ich die angepassten Files über den contao-manager installieren lasse funktioniert es nicht. Aber nur bei diesen beiden Tabellen.Bei allen anderen funktioniert der header.
    Ich verstehe das nicht. :-(

  13. #13
    Alter Contao-Hase
    Registriert seit
    24.02.2021.
    Beiträge
    1.477
    Partner-ID
    11715
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Gibt es noch einen anderen Cache (nicht dev/prod) wie z.B. der OpCache, der dahinter stecken könnte (Gerade wegen dem Umbenennen der Dateien)?

    Ist der Code in seiner Gänze öffentlich einsehbar?

  14. #14
    Contao-Nutzer
    Registriert seit
    18.12.2010.
    Ort
    Mühltal
    Beiträge
    55

    Standard

    Zitat Zitat von zoglo Beitrag anzeigen
    Gibt es noch einen anderen Cache (nicht dev/prod) wie z.B. der OpCache, der dahinter stecken könnte (Gerade wegen dem Umbenennen der Dateien)?

    Ist der Code in seiner Gänze öffentlich einsehbar?
    Ich habe nun beide Tabellen komplett neu erstellt. Dazu habe ich als vorläge zwei Dateien genommen, bei denen der Header bereits funktioniert hat und nur die Felder geändert. Nun funktioniert es und der Header wird korrekt angezeigt. Der einzige unterschied zur vorherigen Version ist, dass der Titel kein Datum mehr enthält.

    Der Code ist im git Repositoy diversworld/contao-diveclub-bundle.

  15. #15
    Alter Contao-Hase
    Registriert seit
    24.02.2021.
    Beiträge
    1.477
    Partner-ID
    11715
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Zitat Zitat von diversworld Beitrag anzeigen
    Ich habe nun beide Tabellen komplett neu erstellt. Dazu habe ich als vorläge zwei Dateien genommen, bei denen der Header bereits funktioniert hat und nur die Felder geändert. Nun funktioniert es und der Header wird korrekt angezeigt. Der einzige unterschied zur vorherigen Version ist, dass der Titel kein Datum mehr enthält.

    Der Code ist im git Repositoy diversworld/contao-diveclub-bundle.
    Sieht für mich korrekt aus - aber dann kann man froh seni, dass es einfach funktioniert ..

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •