4.13.29: Controller\ContentElement
Hi,
ich versuche eine vorhandene Extension auf 4.x umzustellen und habe ein Problem mit dem ContentElement:
PHP-Code:
src/ContaoManager
src/Controller
src/DependencyInjection
src/Module
src/Resources
src/Resources/config
src/Resources/contao
src/Resources/contao/config
src/Resources/contao/dca
src/Resources/contaolanguages
src/Resources/contao/languages/en
src/Resources/contao/models
src/Resources/contao/templates
src/Resources/public
src/Resources/public/images
src/Controller/VoteController.php
PHP-Code:
<?php
declare(strict_types=1);
/*
* Vote Bundle
*
* @copyright (c) 2023 - 2023 Florian Daeumling, Germany. All right reserved
* @license https://github.com/toteph42/vote/blob/master/LICENSE
*/
namespace VoteBundle\Controller\ContentElement;
use Contao\CoreBundle\Controller\ContentElement\AbstractContentElementController;
use Contao\ContentModel;
use Contao\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* @ContentElement("vote", category="texts", template="ce_votes")
*/
class VoteController extends AbstractContentElementController {
public const TYPE = 'vote';
protected function getResponse(Template $template, ContentModel $model, Request $request): Response {
$template->text = $model->text;
return $template->getResponse();
}
}
?>
src/Resources/config/services.yaml
PHP-Code:
services:
_defaults:
autoconfigure: true
VoteBundle\Controller\ContentElement\VoteController:
tags:
-
name: contao.content_element
category: texts
src/Resources/contao/dca/
PHP-Code:
<?php
declare(strict_types=1);
/*
* Vote Bundle
*
* @copyright (c) 2023 - 2023 Florian Daeumling, Germany. All right reserved
* @license https://github.com/toteph42/vote/blob/master/LICENSE
*/
/**
* Add a palette to tl_content
*/
use Contao\Backend;
use VoteBundle\Controller\ContentElement\VoteController;
$GLOBALS['TL_DCA']['tl_content']['palettes'][VoteController::TYPE] = '{type_legend},type,headline;{include_legend},'.
'vote,vote_current;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,space';
/**
* Add a field to tl_content
*/
$GLOBALS['TL_DCA']['tl_content']['fields']['vote'] = [
'label' => &$GLOBALS['TL_LANG']['tl_content']['vote'],
'exclude' => true,
'inputType' => 'select',
'options_callback' => [ 'tl_content_class', 'getVotes' ],
'eval' => [ 'includeBlankOption' => true, 'chosen' => true, 'tl_class' => 'w50' ],
'sql' => "int(10) unsigned NOT NULL default '0'"
];
$GLOBALS['TL_DCA']['tl_content']['fields']['vote_current'] = [
'label' => &$GLOBALS['TL_LANG']['tl_content']['vote_current'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => [ 'tl_class' => 'w50 m12' ],
'sql' => "char(1) NOT NULL default ''"
];
/**
* Provide miscellaneous methods that are used by the data configuration array.
*/
class tl_content_class extends Backend {
/**
* Get all votes and return them as array
* @return array
*/
public function getVotes(): array {
$arr = [];
$obj= $this->Database->execute("SELECT id, title FROM tl_vote ORDER BY title");
while ($obj->next())
$arr[$obj->id] = $obj->title;
return $arr;
}
}
?>
src/Resources/contao/languages/en/default.php
PHP-Code:
<?php
/*
* Vote Bundle
*
* @copyright (c) 2023 - 2023 Florian Daeumling, Germany. All right reserved
* @license https://github.com/toteph42/vote/blob/master/LICENSE
*/
use VoteBundle\Controller\ContentElement\VoteController;
// Content elements
$GLOBALS['TL_LANG']['CTE'][VoteController::TYPE] = [ 'Vote', 'Displays a voting.' ];
src/Resources/contao/templates/ce_votes.html5
PHP-Code:
<div class="<?php echo $this->class; ?><?php if ($this->featured): ?> featured<?php endif; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>>
<?php endif; ?>
<?php echo $this->vote; ?>
</div>
Code:
composer install
php.exe vendor/bin/contao-console debug:fragment
content_element wird nicht angezeigt. Im Debug Modus kommt dann die Meldung:
Content element class "" (content element "vote") does not exist
Kann mir bitte jemand helfen?
Liste der Anhänge anzeigen (Anzahl: 3)
Hallo,
vielen Dank!
Ich habe alle Änderungen vorgenommen. Allerdings funktioniert es immer noch nicht. Im Anhang die Bildschirmfotos der Umfrage, des BE und des FE. Updates sind in Github verfügbar.