Skip to content

Commit

Permalink
Merge pull request #83 from oveleon/develop
Browse files Browse the repository at this point in the history
Contao 5.1 support
  • Loading branch information
zoglo authored Mar 13, 2023
2 parents 796fb89 + fd69c96 commit dcb4b2e
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 72 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
}
],
"require":{
"php":">=7.4",
"php":"^7.4 || ^8.0",
"ext-json": "*",
"ext-dom": "*",
"contao/core-bundle":"^4.13"
"contao/core-bundle":"^4.13 || ^5.1"
},
"require-dev": {
"contao/manager-plugin": "^2.0"
Expand Down
23 changes: 23 additions & 0 deletions docs/TEMPLATE_VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@

---

### As Twig is not yet fully supported (Contao ^5.1), this feature will only work with Legacy-Templates)
https://docs.contao.org/dev/framework/templates/legacy/

> To use legacy-templates (html5) in contao ^5.1, you can force this by overwriting config.php in "/contao/config/config.php".
```php
<?php

$GLOBALS['TL_CTE']['texts']['code'] = \Contao\ContentCode::class;
$GLOBALS['TL_CTE']['texts']['headline'] = \Contao\ContentHeadline::class;
$GLOBALS['TL_CTE']['texts']['html'] = \Contao\ContentHtml::class;
$GLOBALS['TL_CTE']['texts']['list'] = \Contao\ContentList::class;
$GLOBALS['TL_CTE']['texts']['text'] = \Contao\ContentText::class;
$GLOBALS['TL_CTE']['texts']['table'] = \Contao\ContentTable::class;

$GLOBALS['TL_CTE']['links']['hyperlink'] = \Contao\ContentHyperlink::class;
$GLOBALS['TL_CTE']['links']['toplink'] = \Contao\ContentToplink::class;

$GLOBALS['TL_CTE']['media']['image'] = \Contao\ContentImage::class;
$GLOBALS['TL_CTE']['media']['gallery'] = \Contao\ContentGallery::class;
$GLOBALS['TL_CTE']['media']['youtube'] = \Contao\ContentYouTube::class;
$GLOBALS['TL_CTE']['media']['vimeo'] = \Contao\ContentVimeo::class;
```

# Passing css group variables to a template:
If the checkbox `Use as template variable` is set, these are not automatically passed to the CSS class of the corresponding element but are available in the template.
To access the variables, we can access the corresponding class collection via the `styleManager` object.
Expand Down
26 changes: 13 additions & 13 deletions src/Controller/BackendModule/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Contao\Config;
use Contao\Controller;
use Contao\CoreBundle\Controller\AbstractBackendController;
use Contao\CoreBundle\Csrf\ContaoCsrfTokenManager;
use Contao\CoreBundle\Exception\RedirectResponseException;
use Contao\Database;
use Contao\File;
Expand All @@ -14,31 +16,29 @@
use DOMDocument;
use Oveleon\ContaoComponentStyleManager\Model\StyleManagerArchiveModel;
use Oveleon\ContaoComponentStyleManager\Model\StyleManagerModel;
use Oveleon\ContaoComponentStyleManager\StyleManager\Config as BundleConfig;
use Oveleon\ContaoComponentStyleManager\StyleManager\Sync;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
use Oveleon\ContaoComponentStyleManager\StyleManager\Config as BundleConfig;
use Twig\Environment as TwigEnvironment;

/**
* @Route("%contao.backend.route_prefix%/style-manager-import", name=ImportController::class, defaults={"_scope": "backend"})
*/
class ImportController extends AbstractController
class ImportController extends AbstractBackendController
{
const ROUTE = 'style-manager-import';
public const ROUTE = 'style-manager-import';

protected TwigEnvironment $twig;
protected RequestStack $requestStack;
protected TranslatorInterface $translator;
private ContaoCsrfTokenManager $tokenManager;

public function __construct(TwigEnvironment $twig, RequestStack $requestStack, TranslatorInterface $translator)
public function __construct(RequestStack $requestStack, TranslatorInterface $translator, ContaoCsrfTokenManager $tokenManager)
{
$this->twig = $twig;
$this->requestStack = $requestStack;
$this->translator = $translator;
$this->tokenManager = $tokenManager;
}

public function __invoke(): Response
Expand Down Expand Up @@ -85,7 +85,7 @@ public function __invoke(): Response
$configs = $this->createImportTree(...$configs);
}

return new Response($this->twig->render('@ContaoComponentStyleManager/import.html.twig', [
return $this->render('@ContaoComponentStyleManager/import.html.twig', [
'headline' => $partial ? $this->translator->trans('tl_style_manager_import.importPartial', [], 'contao_default') : 'Import',
'messages' => Message::generate(),
'useBundleConfig' => System::getContainer()->getParameter('contao_component_style_manager.use_bundle_config'),
Expand All @@ -94,12 +94,12 @@ public function __invoke(): Response
'configs' => $configs,
'form' => [
'id' => 'style_manager_import',
'rt' => System::getContainer()->get('contao.csrf.token_manager')->getDefaultTokenValue(),
'rt' => $this->tokenManager->getDefaultTokenValue(),
'maxFileSize' => Config::get('maxFileSize'),
'uploadWidget' => $objUploader->generateMarkup()
],
'action' => [
'back' => str_replace('/' . self::ROUTE, '', TL_SCRIPT) . '?do=style_manager',
'back' => str_replace('/' . self::ROUTE, '', $this->generateUrl('contao_backend')) . '?do=style_manager',
],
'label' => [
'back' => $this->translator->trans('MSC.backBT', [], 'contao_default'),
Expand All @@ -114,7 +114,7 @@ public function __invoke(): Response
'bundleConfigEmpty' => $this->translator->trans('tl_style_manager_import.bundleConfigEmpty', [], 'contao_default'),
'bundleConfigInactive' => $this->translator->trans('tl_style_manager_import.bundleConfigInactive', [], 'contao_default'),
]
]));
]);
}

/**
Expand Down
14 changes: 12 additions & 2 deletions src/EventListener/DataContainer/StyleManagerArchiveListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@
use Oveleon\ContaoComponentStyleManager\Controller\BackendModule\ImportController;
use Oveleon\ContaoComponentStyleManager\Model\StyleManagerArchiveModel;
use Oveleon\ContaoComponentStyleManager\StyleManager\Config;
use Symfony\Component\Routing\RouterInterface;

class StyleManagerArchiveListener
{

private RouterInterface $router;


public function __construct(RouterInterface $router)
{
$this->router = $router;
}

/**
* @Callback(table="tl_style_manager_archive", target="config.onload")
*/
Expand Down Expand Up @@ -54,7 +64,7 @@ public function importConfigButton(?string $href, string $label, string $title,
}

return vsprintf('<a href="%s" class="%s" title="%s" %s>%s</a> ', [
TL_SCRIPT. '/' . ImportController::ROUTE,
$this->router->generate(ImportController::class),
$class,
StringUtil::specialchars($title),
$attributes,
Expand All @@ -77,7 +87,7 @@ public function bundleConfigButton(?string $href, string $label, string $title,
}

return vsprintf('<a href="%s" class="%s" %s>%s: %s</a>', [
TL_SCRIPT. '/' . ImportController::ROUTE,
$this->router->generate(ImportController::class),
$class,
$attributes,
$label,
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/contao/dca/tl_style_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
* (c) https://www.oveleon.de/
*/

use Contao\DC_Table;

$GLOBALS['TL_DCA']['tl_style_manager'] = [

// Config
'config' => [
'dataContainer' => 'Table',
'dataContainer' => DC_Table::class,
'ptable' => 'tl_style_manager_archive',
'switchToEdit' => true,
'enableVersioning' => true,
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/contao/dca/tl_style_manager_archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* (c) https://www.oveleon.de/
*/

use Contao\DC_Table;

$GLOBALS['TL_DCA']['tl_style_manager_archive'] = [
// Config
'config' => [
'dataContainer' => 'Table',
'dataContainer' => DC_Table::class,
'ctable' => ['tl_style_manager'],
'switchToEdit' => true,
'enableVersioning' => true,
Expand Down
1 change: 1 addition & 0 deletions src/Resources/public/icons/about.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 3 additions & 9 deletions src/Resources/views/import.html.twig
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{% extends "@ContaoCore/Backend/be_page.html.twig" %}
{% extends "@Contao/be_main" %}

{% block headline %}
{{ headline }}
{% endblock %}

{% block error %}{% endblock %}

{% block main %}
{% block main_content %}
{% if messages %}
{{ messages|raw }}
{% endif %}
Expand Down Expand Up @@ -88,7 +82,7 @@
<h3>
{{ label.bundleUpload }}
<a href="/contao/help?table=tl_style_manager_archive&amp;field=bundleConfig" title="" onclick="Backend.openModalIframe({'title':'{{ label.bundleUpload }}','url':this.href});return false">
<img src="system/themes/flexible/icons/about.svg" width="16" height="16">
<img src="/bundles/contaocomponentstylemanager/icons/about.svg" width="16" height="16">
</a>
</h3>
{% if useBundleConfig %}
Expand Down
Loading

0 comments on commit dcb4b2e

Please sign in to comment.