Skip to content

Commit 68a4f00

Browse files
committed
Notify about layout misconfiguration
1 parent 3a0b184 commit 68a4f00

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

contao/dca/tl_layout.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
* (c) https://www.oveleon.de/
77
*/
88

9-
use ContaoThemeManager\Core\EventListener\DataContainer\DataContainerListener;
10-
11-
$GLOBALS['TL_DCA']['tl_layout']['fields']['framework']['load_callback'][] = [DataContainerListener::class, 'checkSelectedFramework'];
12-
139
// Default rows to include header and footer
1410
$GLOBALS['TL_DCA']['tl_layout']['fields']['rows']['default'] = '3rw';
1511

contao/languages/de/tl_layout.xlf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?xml version="1.0" ?><xliff version="1.1">
22
<file datatype="php" original="contao/languages/en/tl_layout.php" source-language="en" target-language="de">
33
<body>
4+
<trans-unit id="tl_layout.misconfiguration">
5+
<source>The layout is configured incorrectly. By using the ThemeManager, incorrect settings can affect the layouting. Please remove all values and units in:&lt;br&gt;&lt;em&gt;%s&lt;/em&gt;, &lt;em&gt;%s&lt;/em&gt;, &lt;em&gt;%s&lt;/em&gt; and &lt;em&gt;%s&lt;/em&gt;.</source>
6+
<target>Das Layout ist falsch konfiguriert. Durch den Einsatz des ThemeManagers können falsche Einstellungen das Layouting beeinflussen. Bitte entfernen Sie alle Werte und Einstellungen in:&lt;br&gt;&lt;em&gt;%s&lt;/em&gt;, &lt;em&gt;%s&lt;/em&gt;, &lt;em&gt;%s&lt;/em&gt; und &lt;em&gt;%s&lt;/em&gt;.</target>
7+
</trans-unit>
48
<trans-unit id="tl_layout.frameworkMessage">
5-
<source>There are superfluous CSS frameworks in this layout. By using the ThemeManager the following frameworks are not needed: %s</source>
6-
<target>Es befinden sich überflüssige CSS-Frameworks in diesem Layout. Durch den Einsatz des ThemeManagers werden folgende Frameworks nicht benötigt: %s</target>
9+
<source>There are superfluous CSS frameworks in this layout. By using the ThemeManager the following frameworks are not needed:&lt;br&gt;%s</source>
10+
<target>Es befinden sich überflüssige CSS-Frameworks in diesem Layout. Durch den Einsatz des ThemeManagers werden folgende Frameworks nicht benötigt:&lt;br&gt;%s</target>
711
</trans-unit>
812
</body>
913
</file>

contao/languages/en/tl_layout.xlf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?xml version="1.0" ?><xliff version="1.1">
22
<file datatype="php" original="contao/languages/en/tl_layout.php" source-language="en">
33
<body>
4+
<trans-unit id="tl_layout.misconfiguration">
5+
<source>The layout is configured incorrectly. By using the ThemeManager, incorrect settings can affect the layouting. Please remove all values and units in:&lt;br&gt;&lt;em&gt;%s&lt;/em&gt;, &lt;em&gt;%s&lt;/em&gt;, &lt;em&gt;%s&lt;/em&gt; and &lt;em&gt;%s&lt;/em&gt;.</source>
6+
</trans-unit>
47
<trans-unit id="tl_layout.frameworkMessage">
5-
<source>There are superfluous CSS frameworks in this layout. By using the ThemeManager the following frameworks are not needed: %s</source>
8+
<source>There are superfluous CSS frameworks in this layout. By using the ThemeManager the following frameworks are not needed:&lt;br&gt;%s</source>
69
</trans-unit>
710
</body>
811
</file>

src/EventListener/DataContainer/DataContainerListener.php

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
namespace ContaoThemeManager\Core\EventListener\DataContainer;
44

55
use Contao\ContentModel;
6+
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
67
use Contao\CoreBundle\Framework\ContaoFramework;
78
use Contao\CoreBundle\Security\ContaoCorePermissions;
8-
use Contao\Database;
99
use Contao\DataContainer;
1010
use Contao\Input;
11+
use Contao\Message;
1112
use Contao\StringUtil;
1213
use Contao\System;
13-
use ContaoThemeManager\Core\Migration\ThemeConfigurationMigration;
1414
use Doctrine\DBAL\Connection;
1515
use Symfony\Component\Security\Core\Security;
16-
use Contao\Message;
1716

1817
class DataContainerListener
1918
{
@@ -23,6 +22,40 @@ public function __construct(
2322
protected Security $security
2423
){}
2524

25+
#[AsCallback(table: 'tl_layout', target: 'fields.headerHeight.load')]
26+
#[AsCallback(table: 'tl_layout', target: 'fields.footerHeight.load')]
27+
#[AsCallback(table: 'tl_layout', target: 'fields.widthLeft.load')]
28+
#[AsCallback(table: 'tl_layout', target: 'fields.widthRight.load')]
29+
public function checkLayoutMisconfiguration($value, DataContainer $dc): array|string
30+
{
31+
if (empty($value))
32+
{
33+
return '';
34+
}
35+
36+
$array = StringUtil::deserialize($value);
37+
38+
if (
39+
empty($array) ||
40+
!is_array($array) ||
41+
(empty($array['unit'] ?? '') && empty($array['value'] ?? ''))
42+
) {
43+
return $value;
44+
}
45+
46+
Message::addError(
47+
vsprintf(($GLOBALS['TL_LANG']['tl_layout']['misconfiguration'] ?? null), [
48+
($GLOBALS['TL_LANG']['tl_layout']['headerHeight'][0] ?? null),
49+
($GLOBALS['TL_LANG']['tl_layout']['footerHeight'][0] ?? null),
50+
($GLOBALS['TL_LANG']['tl_layout']['widthLeft'][0] ?? null),
51+
($GLOBALS['TL_LANG']['tl_layout']['widthRight'][0] ?? null)
52+
])
53+
);
54+
55+
return $array;
56+
}
57+
58+
#[AsCallback(table: 'tl_layout', target: 'fields.framework.load')]
2659
public function checkSelectedFramework($value, DataContainer $dc): array|string
2760
{
2861
if (empty($value))

0 commit comments

Comments
 (0)