Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: CI
on: [push]

jobs:
phpstan:
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2

- name: Checkout
uses: actions/checkout@v6

- name: Install the dependencies
uses: ramsey/composer-install@v3
with:
composer-options: "--no-plugins"

- name: PHPStan
run: vendor/bin/phpstan analyse -c phpstan.neon

rector:
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2

- name: Checkout
uses: actions/checkout@v6

- name: Install the dependencies
uses: ramsey/composer-install@v3
with:
composer-options: "--no-plugins"

- name: Rector
run: vendor/bin/rector --dry-run --no-progress-bar

ecs:
name: ECS
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, mysqli, pcre, pdo_mysql, zlib
coverage: none

- name: Checkout
uses: actions/checkout@v6
with:
show-progress: false

- name: Install the dependencies
uses: ramsey/composer-install@v3
with:
composer-options: "--no-plugins"

- name: Run ECS
run: vendor/bin/ecs check --no-progress-bar
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
"contao/core-bundle": "^5.3",
"symfony/http-kernel": "^6.4 || ^7.0"
},
"require-dev": {
"contao/core-bundle": "5.3.*",
"rector/rector": "^2.5",
"contao/contao-rector": "dev-main",
"symplify/easy-coding-standard": "^13.2",
"phpstan/phpstan": "^2.2",
"phpstan/phpstan-symfony": "^2.0",
"contao/manager-plugin": "^2.13",
"terminal42/contao-leads": "^3.2"
},
"autoload": {
"psr-4": {
"HeimrichHannot\\FormFieldsCollectionBundle\\": "src/"
Expand Down
19 changes: 13 additions & 6 deletions contao/dca/tl_form_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@

$dca = &$GLOBALS['TL_DCA']['tl_form_field'];

$dca['palettes'][DateTimeWidget::TYPE] = '{type_legend},type,name,label;{fconfig_legend},mandatory,dateTimeType,defaultDateTimeValue;{expert_legend:hide},class,minval,maxval,accesskey,tabindex;{template_legend:hide},customTpl;{invisible_legend:hide},invisible';
$dca['palettes'][DateTimeWidget::TYPE] = <<<PALETTE
{type_legend},type,name,label;
{fconfig_legend},mandatory,dateTimeType,defaultDateTimeValue;
{expert_legend:collapsed},class,minval,maxval,accesskey,tabindex;
{template_legend:collapsed},customTpl;
{invisible_legend:collapsed},invisible
PALETTE;
$dca['palettes'][SingleCheckboxWidget::TYPE] = <<< PALETTE
{type_legend},type,name,label;
{fconfig_legend},mandatory,help;
{options_legend},value,text;
{expert_legend:hide},class;
{template_legend:hide},customTpl;
{invisible_legend:hide},invisible
{expert_legend:collapsed},class;
{template_legend:collapsed},customTpl;
{invisible_legend:collapsed},invisible
PALETTE;

$dca['subpalettes']['defaultDateTimeValue_custom'] = 'value';
Expand All @@ -27,7 +33,9 @@
],
'reference' => &$GLOBALS['TL_LANG']['tl_form_field'],
'default' => 'date',
'eval' => ['tl_class' => 'w50'],
'eval' => [
'tl_class' => 'w50',
],
'sql' => "varchar(4) NOT NULL default ''",
];

Expand All @@ -45,4 +53,3 @@
],
'sql' => "varchar(8) NOT NULL default ''",
];

10 changes: 5 additions & 5 deletions contao/languages/de/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
use HeimrichHannot\FormFieldsCollectionBundle\FrontendWidget\DateTimeWidget;
use HeimrichHannot\FormFieldsCollectionBundle\FrontendWidget\SingleCheckboxWidget;

$GLOBALS['TL_LANG']['FFL'][DateTimeWidget::TYPE] = [
$GLOBALS['TL_LANG']['FFL'][DateTimeWidget::TYPE] = [
'Datum-/ Zeitfeld (Form Fields Collection)',
'Ermöglicht die Eingabe von Datum und/ oder Zeit.'
'Ermöglicht die Eingabe von Datum und/ oder Zeit.',
];
$GLOBALS['TL_LANG']['FFL'][SingleCheckboxWidget::TYPE] = [
$GLOBALS['TL_LANG']['FFL'][SingleCheckboxWidget::TYPE] = [
'Checkbox Einzeln (Form Fields Collection)',
'Eine einzelne Checkbox, die entweder aktiviert oder deaktiviert sein kann.'
];
'Eine einzelne Checkbox, die entweder aktiviert oder deaktiviert sein kann.',
];
2 changes: 1 addition & 1 deletion contao/languages/de/tl_form_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
$lang['defaultDateTimeCustomValue'][0] = 'Benutzerdefinierte Zeit';
$lang['defaultDateTimeCustomValue'][1] = 'Bitte geben Sie die benutzerdefinierte Zeit ein.';
$lang['singleCheckboxValue'][0] = 'Checkbox Wert';
$lang['singleCheckboxValue'][1] = 'Legen Sie den Checkbox-Wert fest. Wenn leer, wird der Wert 1 sein.';
$lang['singleCheckboxValue'][1] = 'Legen Sie den Checkbox-Wert fest. Wenn leer, wird der Wert 1 sein.';
10 changes: 5 additions & 5 deletions contao/languages/en/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
use HeimrichHannot\FormFieldsCollectionBundle\FrontendWidget\DateTimeWidget;
use HeimrichHannot\FormFieldsCollectionBundle\FrontendWidget\SingleCheckboxWidget;

$GLOBALS['TL_LANG']['FFL'][DateTimeWidget::TYPE] = [
$GLOBALS['TL_LANG']['FFL'][DateTimeWidget::TYPE] = [
'Date/ time (Form Fields Collection)',
'A date or time field.'
'A date or time field.',
];
$GLOBALS['TL_LANG']['FFL'][SingleCheckboxWidget::TYPE] = [
$GLOBALS['TL_LANG']['FFL'][SingleCheckboxWidget::TYPE] = [
'Checkbox Single (Form Fields Collection)',
'A single checkbox that can be either checked or unchecked.'
];
'A single checkbox that can be either checked or unchecked.',
];
2 changes: 1 addition & 1 deletion contao/languages/en/tl_form_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
$lang['defaultDateTimeCustomValue'][0] = 'Custom date/ time';
$lang['defaultDateTimeCustomValue'][1] = 'Please enter a custom date/ time.';
$lang['singleCheckboxValue'][0] = 'Checkbox Value';
$lang['singleCheckboxValue'][1] = 'Set the checkbox value. If empty, the value will be 1.';
$lang['singleCheckboxValue'][1] = 'Set the checkbox value. If empty, the value will be 1.';
39 changes: 39 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\Basic\BracesPositionFixer;
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/contao',

])

// add a single rule
->withRules([
NoUnusedImportsFixer::class,
BracesPositionFixer::class,
])

// add sets - group of rules
->withPreparedSets(
arrays: true,
comments: true,
docblocks: true,
spaces: true,
namespaces: true,
)
->withPhpCsFixerSets(symfony: true)
->withSkip([
NotOperatorWithSuccessorSpaceFixer::class,
MethodChainingIndentationFixer::class => [
'*/DependencyInjection/Configuration.php',
'src/*Bundle.php'
],
]);
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
level: 4
paths:
- src
- contao
# universalObjectCratesClasses:
# - Contao\Database\Result
# - Contao\Model
# - Contao\Template
includes:
- vendor/phpstan/phpstan-symfony/extension.neon
46 changes: 46 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

use Contao\Rector\Set\ContaoLevelSetList;
use Contao\Rector\Set\ContaoSetList;
use Rector\Config\RectorConfig;
use Rector\Php81\Rector\Array_\ArrayToFirstClassCallableRector;
use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/contao',

])
->withPhpVersion(PhpVersion::PHP_84)
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
# In Vorbereitung für PHP 8.4:
ExplicitNullableParamTypeRector::class,
])

->withImportNames(
importShortClasses: false,
removeUnusedImports: true
)
->withComposerBased(
twig: true,
doctrine: true,
phpunit: true,
symfony: true,
)
->withSets([
LevelSetList::UP_TO_PHP_82,
ContaoLevelSetList::UP_TO_CONTAO_53,
ContaoSetList::FQCN,
ContaoSetList::ANNOTATIONS_TO_ATTRIBUTES,
])
->withSkip([
ArrayToFirstClassCallableRector::class,
])
;
2 changes: 1 addition & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public function registerContainerConfiguration(LoaderInterface $loader, array $m
{
$loader->load('@HeimrichHannotFormFieldsCollectionBundle/config/services.yaml');
}
}
}
9 changes: 5 additions & 4 deletions src/EventListener/DateTimeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ class DateTimeListener
#[AsCallback(table: 'tl_form_field', target: 'config.onload')]
public function onLoadCallback(DataContainer $dc): void
{
if (!$dc || !$dc->id) {
if (!$dc->id) {
return;
}

/** @var \HeimrichHannot\FormFieldsCollectionBundle\Model\FormFieldModel|null $widget */
$widget = FormFieldModel::findByPk($dc->id);
if (!$widget || (DateTimeWidget::TYPE !== $widget->type)) {
if (DateTimeWidget::TYPE !== $widget?->type) {
return;
}

Expand All @@ -34,6 +35,6 @@ public function onLoadCallback(DataContainer $dc): void
$GLOBALS['TL_DCA']['tl_form_field']['fields']['maxval']['eval']['rgxp'] = 'time';
$GLOBALS['TL_DCA']['tl_form_field']['fields']['value']['label'] = &$GLOBALS['TL_LANG']['tl_form_field']['defaultDateTimeCustomValue'];
break;
};
}
}
}
}
14 changes: 9 additions & 5 deletions src/EventListener/Integrations/LeadsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ public function onFormDataValueEvent(FormDataValueEvent $event): void
$format = match ($event->getField()['dateTimeType']) {
'date' => Date::getNumericDateFormat(),
'time' => Date::getNumericTimeFormat(),
'default' => null,
default => null,
};

if (null === $format) {
$event->stopPropagation();

return;
}

try {
$event->setValue((new Date($event->getValue(), $format))->tstamp);
} catch (\Exception) {}
} catch (\Exception) {
}

$event->stopPropagation();
}
Expand All @@ -45,18 +47,20 @@ public function onFormDataLabelEvent(FormDataLabelEvent $event): void
$format = match ($event->getField()['dateTimeType']) {
'date' => Date::getNumericDateFormat(),
'time' => Date::getNumericTimeFormat(),
'default' => null,
default => null,
};

if (null === $format) {
$event->stopPropagation();

return;
}

try {
$event->setLabel(Date::parse($format, $event->getValue()));
} catch (\Exception) {}
} catch (\Exception) {
}

$event->stopPropagation();
}
}
}
4 changes: 2 additions & 2 deletions src/EventListener/SingleCheckboxListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SingleCheckboxListener
#[AsCallback(table: 'tl_form_field', target: 'config.onload')]
public function onLoadCallback(DataContainer $dc): void
{
if (!$dc || !$dc->id) {
if (!$dc->id) {
return;
}

Expand All @@ -26,4 +26,4 @@ public function onLoadCallback(DataContainer $dc): void
$GLOBALS['TL_DCA']['tl_form_field']['fields']['text']['eval']['mandatory'] = true;
$GLOBALS['TL_DCA']['tl_form_field']['fields']['value']['label'] = &$GLOBALS['TL_LANG']['tl_form_field']['singleCheckboxValue'];
}
}
}
10 changes: 10 additions & 0 deletions src/FormFieldModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace HeimrichHannot\FormFieldsCollectionBundle\Model;

/**
* @property string $dateTimeType
*/
class FormFieldModel extends \Contao\FormFieldModel
{
}
Loading
Loading