Skip to content

Commit 2e66992

Browse files
committed
Unlock Contao 5.
1 parent 4554c8d commit 2e66992

File tree

8 files changed

+199
-43
lines changed

8 files changed

+199
-43
lines changed

.php-cs-fixer.dist.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
$header = <<<EOF
4+
This file is part of the Contao Swiper Bundle.
5+
6+
(c) inspiredminds
7+
8+
@license LGPL-3.0-or-later
9+
EOF;
10+
11+
$finder = PhpCsFixer\Finder::create()
12+
->exclude('Resources/contao/templates')
13+
->in([
14+
__DIR__.'/src',
15+
])
16+
;
17+
18+
return (new PhpCsFixer\Config())
19+
->setRules([
20+
'@Symfony' => true,
21+
'@Symfony:risky' => true,
22+
'@PHP71Migration' => true,
23+
'@PHP71Migration:risky' => true,
24+
'@PHPUnit60Migration:risky' => true,
25+
'align_multiline_comment' => true,
26+
'array_indentation' => true,
27+
'array_syntax' => ['syntax' => 'short'],
28+
'combine_consecutive_issets' => true,
29+
'combine_consecutive_unsets' => true,
30+
'comment_to_phpdoc' => true,
31+
'compact_nullable_typehint' => true,
32+
'escape_implicit_backslashes' => true,
33+
'fully_qualified_strict_types' => true,
34+
'general_phpdoc_annotation_remove' => [
35+
'annotations' => [
36+
'author',
37+
'expectedException',
38+
'expectedExceptionMessage',
39+
],
40+
],
41+
'header_comment' => ['header' => $header],
42+
'heredoc_to_nowdoc' => true,
43+
'linebreak_after_opening_tag' => true,
44+
'list_syntax' => ['syntax' => 'short'],
45+
'multiline_comment_opening_closing' => true,
46+
'multiline_whitespace_before_semicolons' => [
47+
'strategy' => 'new_line_for_chained_calls',
48+
],
49+
'native_function_invocation' => [
50+
'include' => ['@compiler_optimized'],
51+
],
52+
'no_alternative_syntax' => true,
53+
'no_binary_string' => true,
54+
'no_null_property_initialization' => true,
55+
'no_superfluous_elseif' => true,
56+
'no_superfluous_phpdoc_tags' => true,
57+
'no_unreachable_default_argument_value' => true,
58+
'no_useless_else' => true,
59+
'no_useless_return' => true,
60+
'ordered_class_elements' => true,
61+
'ordered_imports' => true,
62+
'php_unit_strict' => true,
63+
'phpdoc_add_missing_param_annotation' => true,
64+
'phpdoc_order' => true,
65+
'phpdoc_trim_consecutive_blank_line_separation' => true,
66+
'phpdoc_types_order' => [
67+
'null_adjustment' => 'always_last',
68+
'sort_algorithm' => 'none',
69+
],
70+
'return_assignment' => true,
71+
'strict_comparison' => true,
72+
'strict_param' => true,
73+
'string_line_ending' => true,
74+
'void_return' => true,
75+
])
76+
->setFinder($finder)
77+
->setRiskyAllowed(true)
78+
->setUsingCache(false)
79+
;

composer.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
},
2121
"require": {
2222
"php": "^7.2 || ^8.0",
23-
"contao/core-bundle": "^4.9",
24-
"fiedsch/contao-jsonwidget": "^0.4",
25-
"menatwork/contao-multicolumnwizard": "^3.3",
26-
"symfony/config": "^4.4 || ^5.2",
27-
"symfony/dependency-injection": "^4.4 || ^5.2",
28-
"symfony/http-foundation": "^4.4 || ^5.2",
29-
"symfony/http-kernel": "^4.4 || ^5.2"
23+
"contao/core-bundle": "^4.9 || ^5.0",
24+
"mvo/contao-group-widget": "^1.4",
25+
"symfony/config": "^4.4 || ^5.2 || ^6.0",
26+
"symfony/dependency-injection": "^4.4 || ^5.2 || ^6.0",
27+
"symfony/http-foundation": "^4.4 || ^5.2 || ^6.0",
28+
"symfony/http-kernel": "^4.4 || ^5.2 || ^6.0"
3029
},
3130
"require-dev": {
3231
"contao/manager-plugin": "^2.0"

src/Elements/WrapperStart.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class WrapperStart extends ContentElement
3636
*/
3737
public function generate(): string
3838
{
39-
if (TL_MODE === 'BE')
39+
$request = System::getContainer()->get('request_stack')->getCurrentRequest();
40+
41+
if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
4042
{
4143
return (new BackendTemplate('be_wildcard'))->parse();
4244
}

src/Elements/WrapperStop.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class WrapperStop extends ContentElement
3838
*/
3939
public function generate(): string
4040
{
41-
if (TL_MODE === 'BE')
41+
$request = System::getContainer()->get('request_stack')->getCurrentRequest();
42+
43+
if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
4244
{
4345
return (new BackendTemplate('be_wildcard'))->parse();
4446
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace InspiredMinds\ContaoSwiperBundle\Migration;
6+
7+
use Contao\CoreBundle\Migration\AbstractMigration;
8+
use Contao\CoreBundle\Migration\MigrationResult;
9+
use Contao\StringUtil;
10+
use Doctrine\DBAL\Connection;
11+
12+
class GroupWidgetMigration extends AbstractMigration
13+
{
14+
private $db;
15+
16+
public function __construct(Connection $db)
17+
{
18+
$this->db = $db;
19+
}
20+
21+
public function shouldRun(): bool
22+
{
23+
$schemaManager = $this->db->getSchemaManager();
24+
25+
if (!$schemaManager->tablesExist(['tl_content'])) {
26+
return false;
27+
}
28+
29+
$columns = $schemaManager->listTableColumns('tl_content');
30+
31+
if (!isset($columns['sliderbreakpoints'])) {
32+
return false;
33+
}
34+
35+
return (int) $this->db->fetchOne("SELECT COUNT(*) FROM tl_content WHERE sliderBreakpoints LIKE 'a:1:{i:0;%'") > 0;
36+
}
37+
38+
public function run(): MigrationResult
39+
{
40+
foreach ($this->db->fetchAllAssociative("SELECT * FROM tl_content WHERE sliderBreakpoints LIKE 'a:1:{i:0;%'") as $field) {
41+
$templates = [];
42+
43+
foreach (StringUtil::deserialize($field['sliderBreakpoints'], true) as $key => $template) {
44+
if (is_numeric($key)) {
45+
$key = $key + 1;
46+
}
47+
48+
$templates[$key] = $template;
49+
}
50+
51+
$this->db->update('tl_content', ['sliderBreakpoints' => serialize($templates)], ['id' => $field['id']]);
52+
}
53+
54+
return $this->createResult(true);
55+
}
56+
}

src/Resources/contao/dca/tl_content.php

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12+
use Contao\StringUtil;
1213

1314
$GLOBALS['TL_DCA']['tl_content']['palettes']['swiperStart'] = '{type_legend},type;{slider_legend},sliderDelay,sliderSpeed,sliderSlidesPerView,sliderSpaceBetween,sliderEffect,sliderWrapperClass,sliderContinuous,sliderButtons,sliderAutoheight,sliderCenteredSlides,sliderScrollbar,sliderPagination,sliderBreakpoints;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,sliderCustomOptions;{invisible_legend:hide},invisible,start,stop';
1415

@@ -112,41 +113,30 @@
112113
'sql' => "varchar(16) NOT NULL default ''"
113114
);
114115

115-
$GLOBALS['TL_DCA']['tl_content']['fields']['sliderBreakpoints'] = array
116-
(
117-
'label' => &$GLOBALS['TL_LANG']['tl_content']['sliderBreakpoints'],
116+
$GLOBALS['TL_DCA']['tl_content']['fields']['sliderBreakpoints'] = [
118117
'exclude' => true,
119-
'inputType' => 'multiColumnWizard',
120-
'eval' => array
121-
(
122-
'tl_class' => 'clr',
123-
'columnFields' => array
124-
(
125-
'breakpoint' => array
126-
(
127-
'label' => &$GLOBALS['TL_LANG']['tl_content']['sliderBreakpointsSettings']['breakpoint'],
128-
'exclude' => true,
129-
'inputType' => 'text',
130-
'eval' => array('rgxp'=>'natural')
131-
),
132-
'slidesPerView' => array
133-
(
134-
'label' => &$GLOBALS['TL_LANG']['tl_content']['sliderBreakpointsSettings']['slidesPerView'],
135-
'exclude' => true,
136-
'inputType' => 'text',
137-
'eval' => array('maxlength'=>4)
138-
),
139-
'spaceBetween' => array
140-
(
141-
'label' => &$GLOBALS['TL_LANG']['tl_content']['sliderBreakpointsSettings']['spaceBetween'],
142-
'exclude' => true,
143-
'inputType' => 'text',
144-
'eval' => array('rgxp'=>'digit')
145-
),
146-
)
147-
),
118+
'inputType' => 'group',
119+
'palette' => ['breakpoint', 'slidesPerView', 'spaceBetween'],
120+
'eval' => ['tl_class' => 'clr'],
121+
'fields' => [
122+
'breakpoint' => [
123+
'label' => &$GLOBALS['TL_LANG']['tl_content']['sliderBreakpointsSettings']['breakpoint'],
124+
'inputType' => 'text',
125+
'eval' => array('rgxp'=>'natural', 'tl_class' => 'w50')
126+
],
127+
'slidesPerView' => [
128+
'label' => &$GLOBALS['TL_LANG']['tl_content']['sliderBreakpointsSettings']['slidesPerView'],
129+
'inputType' => 'text',
130+
'eval' => array('maxlength'=>4, 'tl_class' => 'clr w50')
131+
],
132+
'spaceBetween' => [
133+
'label' => &$GLOBALS['TL_LANG']['tl_content']['sliderBreakpointsSettings']['spaceBetween'],
134+
'inputType' => 'text',
135+
'eval' => array('rgxp'=>'digit', 'tl_class' => 'w50')
136+
],
137+
],
148138
'sql' => 'BLOB null'
149-
);
139+
];
150140

151141
$GLOBALS['TL_DCA']['tl_content']['fields']['sliderAutoheight'] = array
152142
(
@@ -169,7 +159,29 @@
169159
$GLOBALS['TL_DCA']['tl_content']['fields']['sliderCustomOptions'] = [
170160
'label' => &$GLOBALS['TL_LANG']['tl_content']['sliderCustomOptions'],
171161
'exclude' => true,
172-
'inputType' => 'jsonWidget',
162+
'inputType' => 'textarea',
173163
'eval' => ['tl_class' => 'clr', 'rte' => 'ace|json', 'decodeEntities' => true, 'allowHtml' => true],
174164
'sql' => "blob NULL",
165+
'load_callback' => [static function($value) {
166+
if (empty($value)) {
167+
return null;
168+
}
169+
170+
return json_encode(json_decode($value), JSON_PRETTY_PRINT) ?: null;
171+
}],
172+
'save_callback' => [static function($value) {
173+
$value = StringUtil::decodeEntities($value);
174+
175+
if (empty($value)) {
176+
return null;
177+
}
178+
179+
$value = json_decode($value);
180+
181+
if (null === $value) {
182+
throw new \Exception($GLOBALS['TL_LANG']['ERR']['invalidJsonData']);
183+
}
184+
185+
return json_encode($value);
186+
}],
175187
];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$GLOBALS['TL_LANG']['ERR']['invalidJsonData'] = 'Ungültiges JSON Format!';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$GLOBALS['TL_LANG']['ERR']['invalidJsonData'] = 'Invalid JSON data!';

0 commit comments

Comments
 (0)