Moin ,
Ich probiere gerade mein erstes Backend Modul zu erstellen.
Habt ihr vllt ein einfaches(aktuelles) code Beispiel für ein Backend Modul mit custom backend routes mit Twig Templates?
https://docs.contao.org/dev/guides/back-end-routes/
Moin ,
Ich probiere gerade mein erstes Backend Modul zu erstellen.
Habt ihr vllt ein einfaches(aktuelles) code Beispiel für ein Backend Modul mit custom backend routes mit Twig Templates?
https://docs.contao.org/dev/guides/back-end-routes/
Geändert von Medy (09.11.2021 um 08:48 Uhr)
vll. hilft dir das: https://github.com/markocupic/backen...ecovery-bundle
Oder das hier:
Aber nur im 5er branch
https://github.com/markocupic/import...undle/tree/5.0
Anfragen für bezahlten Support oder Extension-Programmierung via PN.
Kann man Widgets und Twig Templates zusammen nutzen ? ( In einem Backend Modul )
Sodass ich Beisipielsweise 1 Inputfeld habe (text Widget)
und darunter ein Twig template welches z.B den text aus dem input field anzeigt mit hinzugefügten css.
Ich möchte custom html im backend Modul ausgeben.
Geändert von Medy (08.11.2021 um 15:22 Uhr)
Ich denke schon:
Wenn ich dich richtig verstanden habe, möchtest du ein gerendertes Twig Template in ein klassisches Backend Widget Template einbauen.
Code:// src/Widget/Backend/CustomWidget.php namespace App\Widget\Backend; use Contao\StringUtil; use Contao\Widget; use Twig\Environment as TwigEnvironment; class CustomWidget extends Widget { protected $twig; protected $blnSubmitInput = true; protected $blnForAttribute = true; protected $strTemplate = 'be_widget'; public function __construct(TwigEnvironment $twig) { $this->twig = $twig; } public function generate(): string { // Hier kommt etwas Twig... $htmlTwig = $this->twig->render( '@Contao_App/mycustom_backend_widget.html.twig', [ 'foo' => 'bla', 'bar' => 'hoppla', ] ); return sprintf( '<input type="text" name="%s" id="ctrl_%s" class="tl_custom_widget%s" value="%s"><br>%s', $this->name, $this->id, ($this->class ? ' ' . $this->class : ''), StringUtil::specialchars($this->value), // parsed twig template $htmlTwig, ); } }Code:// Twig Template: src/Resources/contao/templates/mycustom_backend_widget.html.twig <h1>{{ bar }}</h1> <p>{{ foo }}</p>
Geändert von markocupic (08.11.2021 um 19:19 Uhr)
Anfragen für bezahlten Support oder Extension-Programmierung via PN.
Sagen wir die obere hälfte sieht so aus :
(ein paar inputs usw)
https://imgur.com/N1hvFqv
und darunter kommt dann ein bisschen HTML wie hier zb.
https://imgur.com/1AgN8om
Oben wollte ich eingaben machen und das custom HTML sollte dann eine vorschau anzeigen.
Ich hatte eigentlich gedacht das ich vllt kein widget brauche um das html bzw twig template mit einzubinden.
Habe noch von den field callback xlabel gelesen.
In dem Tutorial hier konnte man ein Twig Template über Backend Routes im Backen Modul Anzeigen... : https://docs.contao.org/dev/guides/b...es/#body-inner
ich wollte dazu halt noch wie bereits erwähnt in der oberen hälfte Felder aus der Dca Config anzeigen lassen. (Sofern das überhaupt sinn macht oder der richtige weg ist ) ?
Ansonsten würden Custom Widgets evtl wohl meinen Zweck erfüllen.
Weiss nicht welche von den verschiedenen möglichkeiten ich nutzen sollte für die Ausgabe von custom HTML im Backend Modul. Was der richtige Ansatz ist.
Vllt hast du dazu auch ein Beispiel ? Mit Custom html im Backend Modul ?
Geändert von Medy (09.11.2021 um 08:31 Uhr)
Ja, ich würde hier auf jeden Fall den Weg über den input_field callback gehen.
markocupic/contao-bundle-creator-bundle sei Dank:
Ich habe dir in ein paar Minuten ein Bundle gecodet, welches du über den Manager als Paket hochladen kannst (Composer Artifact). Danach das Installtool laufen lassen und fertig ist.
In src/DataContainer/TlMyTest.php kannst du nachvollziehen, wie du das in deinem eigenen Projekt angehen könntest. ;-)
contao-my-test.zip
src/DataContainer/TlMyTest.php:
src/Resources/contao/dca/tl_my_test.php:Code:<?php declare(strict_types=1); /* * This file is part of Contao My Test Bundle. * * (c) Medy 2021 <medy@gmail.com> * @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/medy/contao-my-test */ namespace Medy\ContaoMyTest\DataContainer; use Contao\CoreBundle\ServiceAnnotation\Callback; use Contao\DataContainer; use Medy\ContaoMyTest\Model\MyTestModel; use Twig\Environment as TwigEnvironment; use Twig\Error\LoaderError; use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; class TlMyTest { /** * @var TwigEnvironment */ private $twig; /** * TlMyTest constructor. */ public function __construct(TwigEnvironment $twig) { $this->twig = $twig; } /** * @Callback(table="tl_my_test", target="fields.customHtml.input_field") * * @throws LoaderError * @throws RuntimeError * @throws SyntaxError */ public function generateCustomHtmlMarkup(DataContainer $dc): string { $objModel = MyTestModel::findByPk($dc->id); return $this->twig->render( '@MedyContaoMyTest/custom_html.html.twig', [ 'title' => $objModel ? $objModel->title : 'still empty', ] ); } }
src/Resources/config/services.yml:Code:<?php declare(strict_types=1); /* * This file is part of Contao My Test Bundle. * * (c) Medy 2021 <medy@gmail.com> * @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/medy/contao-my-test */ /** * Table tl_my_test */ $GLOBALS['TL_DCA']['tl_my_test'] = array( // Config 'config' => array( 'dataContainer' => 'Table', 'enableVersioning' => true, 'sql' => array( 'keys' => array( 'id' => 'primary' ) ), ), 'list' => array( 'sorting' => array( 'mode' => 2, 'fields' => array('title'), 'flag' => 1, 'panelLayout' => 'filter;sort,search,limit' ), 'label' => array( 'fields' => array('title'), 'format' => '%s', ), 'global_operations' => array( 'all' => array( 'label' => &$GLOBALS['TL_LANG']['MSC']['all'], 'href' => 'act=select', 'class' => 'header_edit_all', 'attributes' => 'onclick="Backend.getScrollOffset()" accesskey="e"' ) ), 'operations' => array( 'edit' => array( 'label' => &$GLOBALS['TL_LANG']['tl_my_test']['edit'], 'href' => 'act=edit', 'icon' => 'edit.gif' ), 'copy' => array( 'label' => &$GLOBALS['TL_LANG']['tl_my_test']['copy'], 'href' => 'act=copy', 'icon' => 'copy.gif' ), 'delete' => array( 'label' => &$GLOBALS['TL_LANG']['tl_my_test']['delete'], 'href' => 'act=delete', 'icon' => 'delete.gif', 'attributes' => 'onclick="if(!confirm(\'' . $GLOBALS['TL_LANG']['MSC']['deleteConfirm'] . '\'))return false;Backend.getScrollOffset()"' ), 'show' => array( 'label' => &$GLOBALS['TL_LANG']['tl_my_test']['show'], 'href' => 'act=show', 'icon' => 'show.gif', 'attributes' => 'style="margin-right:3px"' ), ) ), // Palettes 'palettes' => array( '__selector__' => array('addSubpalette'), 'default' => '{first_legend},title,selectField,checkboxField,multitextField;{second_legend},addSubpalette;{customHtml_legend},customHtml' ), // Subpalettes 'subpalettes' => array( 'addSubpalette' => 'textareaField', ), // Fields 'fields' => array( 'id' => array( 'sql' => "int(10) unsigned NOT NULL auto_increment" ), 'tstamp' => array( 'sql' => "int(10) unsigned NOT NULL default '0'" ), 'title' => array( 'inputType' => 'text', 'exclude' => true, 'search' => true, 'filter' => true, 'sorting' => true, 'flag' => 1, 'eval' => array('mandatory' => true, 'maxlength' => 255, 'tl_class' => 'w50'), 'sql' => "varchar(255) NOT NULL default ''" ), 'selectField' => array( 'inputType' => 'select', 'exclude' => true, 'search' => true, 'filter' => true, 'sorting' => true, 'reference' => $GLOBALS['TL_LANG']['tl_my_test'], 'options' => array('firstoption', 'secondoption'), 'eval' => array('includeBlankOption' => true, 'tl_class' => 'w50'), 'sql' => "varchar(255) NOT NULL default ''", ), 'checkboxField' => array( 'inputType' => 'select', 'exclude' => true, 'search' => true, 'filter' => true, 'sorting' => true, 'reference' => $GLOBALS['TL_LANG']['tl_my_test'], 'options' => array('firstoption', 'secondoption'), 'eval' => array('includeBlankOption' => true, 'chosen' => true, 'tl_class' => 'w50'), 'sql' => "varchar(255) NOT NULL default ''", ), 'multitextField' => array( 'inputType' => 'text', 'exclude' => true, 'search' => true, 'filter' => true, 'sorting' => true, 'eval' => array('multiple' => true, 'size' => 4, 'decodeEntities' => true, 'tl_class' => 'w50'), 'sql' => "varchar(255) NOT NULL default ''" ), 'addSubpalette' => array( 'exclude' => true, 'inputType' => 'checkbox', 'eval' => array('submitOnChange' => true, 'tl_class' => 'w50 clr'), 'sql' => "char(1) NOT NULL default ''" ), 'textareaField' => array( 'inputType' => 'textarea', 'exclude' => true, 'search' => true, 'filter' => true, 'sorting' => true, 'eval' => array('rte' => 'tinyMCE', 'tl_class' => 'clr'), 'sql' => 'text NULL' ), 'customHtml' => array( 'eval' => array('tl_class' => 'clr', 'doNotShow' => true), ) ) );
Grüsse MarkoCode:services: _defaults: autowire: true autoconfigure: true public: true bind: #$projectDir: '%kernel.project_dir%' _instanceof: Symfony\Bundle\FrameworkBundle\Controller\AbstractController: calls: - [ setContainer, [ '@service_container' ] ] Medy\ContaoMyTest\: resource: ../../ exclude: ../../{DependencyInjection,Resources,Model}
Geändert von markocupic (09.11.2021 um 20:10 Uhr)
Anfragen für bezahlten Support oder Extension-Programmierung via PN.
Ich habe die Zip Datei im Manager hochgeladen
leider bekomme ich eine fehlermeldung. im SChritt Composer install
PHP-Code:
In DownloadManager.php line 148:
Package contao-components/tinymce4-5.10.0.0 does not have an installation s
ource set
PHP-Code:
$ /usr/bin/php7 -q -dmax_execution_time=0 -dmemory_limit=-1 -dallow_url_fopen=1 -ddisable_functions= -ddate.timezone=Europe/Berlin /var/www/contao.loc/web/contao-manager.phar.php composer install --prefer-dist --no-dev --no-progress --no-ansi --no-interaction --optimize-autoloader
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
Package operations: 1 install, 4 updates, 0 removals
As there is no 'unzip' nor '7z' command installed zip files are being unpacked using the PHP zip extension.
This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.
Installing 'unzip' or '7z' may remediate them.
Update of contao-components/tinymce4 failed
- Upgrading symfony-cmf/routing (2.3.3 => 2.3.4): Extracting archive
- Upgrading friendsofsymfony/http-cache-bundle (2.11.1 => 2.11.2): Extracting archive
- Upgrading doctrine/sql-formatter (1.1.1 => 1.1.2): Extracting archive
- Installing medy/contao-my-test (1.0): Extracting archive
In DownloadManager.php line 148:
Package contao-components/tinymce4-5.10.0.0 does not have an installation s
ource set
install [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-scripts] [--no-progress] [--no-install] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>...]
# Process terminated with exit code 1
# Result: General error
Geändert von Medy (10.11.2021 um 11:13 Uhr)
Probier mal vor der Installation eine vollständige Aktualisierung aller Pakete durchzuführen. -> composer update
Ich denke, die Fehlermeldung kommt nicht vom hochgeladenen Package.
Die Installation läuft bei mir sauber durch.
Anfragen für bezahlten Support oder Extension-Programmierung via PN.
Ok konnte den fehler beheben.... indem ich in der asset folder tinymce gelöscht habe und danch ein update ausgeführt habe.
Läuft nun .
Edit : bei einem weiteren composer update verschwindet das hochgeladene bundle wieder.
Ich habe es jetzt verlinkt mit einem eintrag in repositories in der composer.json und habe die entpackten dateien in den ordner gepackt.
Hätte eigentlich vermutet das sich das selbst dort irgendwie einträgt wenn man es über den manager uploaded.? Ist das normal ?
Sollte man kein composer update durchführen wenn man pakete über den manager hochläd und die dateien nicht auf git liegen?
Denke mal später würde sowas nicht passieren ... weil es dann über git läuft und somit die datein immer auffindbar sind.
So ist es ja auch im getting started tutorial gemacht wurden.
PHP-Code:
"repositories": [
{
"type": "path",
"url": "contao-example"
},
Geändert von Medy (11.11.2021 um 08:45 Uhr)
Ist off topic aber ich habe eine Frage zu deiner service.yaml file
(hab es mit deimen Creator bundle erstellt)
PHP-Code:
services:
# Contao frontend module Steffenu\StarterBundle\Controller\FrontendModule\StarterFrontendCollectionController
# We used annotations for tagging the frontend module category, the frontend module type and the frontend module template
Steffenu\StarterBundle\Controller\FrontendModule\StarterFrontendCollectionController:
tags:
- { name: container.service_subscriber }
public: true
# Since Symfony 5 the container has to be set manually
calls:
- [ setContainer, [ '@Psr\Container\ContainerInterface' ] ]
# Contao content element Steffenu\StarterBundle\Controller\ContentElement\TestElementController
# We used annotations for tagging the frontend element category, the frontend element type and the frontend element template
Steffenu\StarterBundle\Controller\ContentElement\TestElementController:
tags:
- { name: container.service_subscriber }
public: true
# Since Symfony 5 the container has to be set manually
calls:
- [ setContainer, [ '@Psr\Container\ContainerInterface' ] ]
# Custom route
Steffenu\StarterBundle\Controller\MyCustomController:
arguments:
- '@twig'
public: true
# Since Symfony 5 the container has to be set manually
calls:
- [ setContainer, [ '@Psr\Container\ContainerInterface' ] ]
# Eingefügt
Steffenu\StarterBundle\DataContainer\TlMyTest:
tags:
- { name: container.service_subscriber }
public: true
# Since Symfony 5 the container has to be set manually
calls:
- [ setContainer, [ '@Psr\Container\ContainerInterface' ] ]
Wieso nutzt du kein Autowiring und autoconfig mehr ??
so wie in dem example was du mir geschickt hast davor ?
PHP-Code:
services:
_defaults:
autowire: true
autoconfigure: true
public: true
bind:
#$projectDir: '%kernel.project_dir%'
_instanceof:
Symfony\Bundle\FrameworkBundle\Controller\AbstractController:
calls:
- [ setContainer, [ '@service_container' ] ]
Medy\ContaoMyTest\:
resource: ../../
exclude: ../../{DependencyInjection,Resources,Model}
Ich stolper auch gerade über diese manuelle service.
und wofür ist :
PHP-Code:
calls:
- [ setContainer, [ '@Psr\Container\ContainerInterface' ] ]
Geändert von Medy (17.11.2021 um 14:38 Uhr)
Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
Lesezeichen