diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..77f2d84 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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.1 + + - name: Checkout + uses: actions/checkout@v4 + + - 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.1 + + - name: Checkout + uses: actions/checkout@v4 + + - 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.1 + extensions: dom, fileinfo, filter, gd, hash, intl, json, mbstring, mysqli, pcre, pdo_mysql, zlib + coverage: none + + - name: Checkout + uses: actions/checkout@v4 + 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 \ No newline at end of file diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 53ad87b..0000000 --- a/.php_cs +++ /dev/null @@ -1,46 +0,0 @@ -exclude('Resources') - ->exclude('Fixtures') - ->in([__DIR__.'/src',]) - ->exclude('vendor') - ->in([__DIR__]) -; - -return PhpCsFixer\Config::create() - ->setRules([ - '@Symfony' => true, - '@Symfony:risky' => true, - 'psr0' => false, - 'strict_comparison' => false, - 'strict_param' => false, - 'array_syntax' => ['syntax' => 'short'], - 'heredoc_to_nowdoc' => true, - 'header_comment' => ['header' => $header], - 'ordered_imports' => true, - 'ordered_class_elements' => true, - 'php_unit_strict' => false, - 'phpdoc_order' => true, - 'no_useless_return' => true, - 'no_useless_else' => true, - 'no_unreachable_default_argument_value' => true, - 'combine_consecutive_unsets' => true, - 'general_phpdoc_annotation_remove' => [ - 'expectedException', - 'expectedExceptionMessage', - ], - 'blank_line_before_statement' => ['statements' => ['break', 'case', 'continue', 'declare', 'default', 'die', 'do', 'exit', 'for', 'foreach', 'goto', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield']] - ]) - ->setFinder($finder) - ->setRiskyAllowed(true) - ->setUsingCache(false) -; diff --git a/composer.json b/composer.json index f25d7d0..ed449a8 100644 --- a/composer.json +++ b/composer.json @@ -20,9 +20,14 @@ }, "require-dev": { "contao/easy-coding-standard": "^6.0", - "contao/manager-plugin": "^2.0", + "contao/manager-plugin": "^2.13", "guzzlehttp/guzzle": "^7.9", - "hofff/contao-consent-bridge": "^1.4" + "hofff/contao-consent-bridge": "^1.4", + "rector/rector": "^2.3", + "contao/contao-rector": "dev-main", + "symplify/easy-coding-standard": "^13.0", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-symfony": "^2.0" }, "conflict": { "ivory/google-map": "<3.0.4", diff --git a/contao/dca/tl_content.php b/contao/dca/tl_content.php index a63d0a7..2e61a5f 100644 --- a/contao/dca/tl_content.php +++ b/contao/dca/tl_content.php @@ -16,7 +16,7 @@ * Palettes */ $dca['palettes'][ContentListener::ELEMENT_GOOGLE_MAP] = - '{type_legend},type,headline;{config_legend},googlemaps_map,googlemaps_skipHtml,googlemaps_skipCss,googlemaps_skipJs;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID;{invisible_legend:hide},invisible,start,stop'; + '{type_legend},type,headline;{config_legend},googlemaps_map,googlemaps_skipHtml,googlemaps_skipCss,googlemaps_skipJs;{template_legend:collapsed},customTpl;{protected_legend:collapsed},protected;{expert_legend:collapsed},guests,cssID;{invisible_legend:collapsed},invisible,start,stop'; /** * Fields. @@ -27,26 +27,37 @@ 'filter' => true, 'inputType' => 'select', 'options_callback' => ['huh.google_maps.data_container.google_map', 'getMapChoices'], - 'eval' => ['tl_class' => 'w50', 'mandatory' => true, 'includeBlankOption' => true, 'chosen' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'mandatory' => true, + 'includeBlankOption' => true, + 'chosen' => true, + ], 'sql' => "int(10) unsigned NOT NULL default '0'", 'wizard' => [['huh.google_maps.data_container.map_wizard', 'addWizard']], ], 'googlemaps_skipHtml' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['googlemaps_skipHtml'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50 clr'], + 'eval' => [ + 'tl_class' => 'w50 clr', + ], 'sql' => "char(1) NOT NULL default ''", ], 'googlemaps_skipCss' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['googlemaps_skipCss'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50'], + 'eval' => [ + 'tl_class' => 'w50', + ], 'sql' => "char(1) NOT NULL default ''", ], 'googlemaps_skipJs' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['googlemaps_skipJs'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50'], + 'eval' => [ + 'tl_class' => 'w50', + ], 'sql' => "char(1) NOT NULL default ''", ], ]; diff --git a/contao/dca/tl_google_map.php b/contao/dca/tl_google_map.php index 097690a..826d4f6 100644 --- a/contao/dca/tl_google_map.php +++ b/contao/dca/tl_google_map.php @@ -7,8 +7,8 @@ * * @license LGPL-3.0-or-later */ - use Contao\Controller; +use Contao\DataContainer; use Contao\DC_Table; use Contao\System; use HeimrichHannot\GoogleMapsBundle\EventListener\DataContainer\GoogleMapListener; @@ -41,7 +41,7 @@ 'format' => '%s', ], 'sorting' => [ - 'mode' => 2, + 'mode' => DataContainer::MODE_SORTABLE, 'fields' => ['title', 'type'], 'headerFields' => ['title'], 'panelLayout' => 'filter;sort,search,limit', @@ -114,14 +114,17 @@ 'dateAdded' => [ 'label' => &$GLOBALS['TL_LANG']['MSC']['dateAdded'], 'sorting' => true, - 'flag' => 6, - 'eval' => ['rgxp' => 'datim', 'doNotCopy' => true], + 'flag' => DataContainer::SORT_DAY_DESC, + 'eval' => [ + 'rgxp' => 'datim', + 'doNotCopy' => true, + ], 'sql' => "int(10) unsigned NOT NULL default '0'", ], 'type' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['type'], 'search' => true, - 'flag' => 12, + 'flag' => DataContainer::SORT_DESC, 'sorting' => true, 'default' => 'base', 'inputType' => 'select', @@ -130,23 +133,33 @@ GoogleMapListener::MAP_TYPE_RESPONSIVE, ], 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['mandatory' => true, 'submitOnChange' => true], + 'eval' => [ + 'mandatory' => true, + 'submitOnChange' => true, + ], 'sql' => "varchar(12) NOT NULL default ''", ], 'title' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['title'], 'search' => true, 'sorting' => true, - 'flag' => 1, + 'flag' => DataContainer::SORT_INITIAL_LETTER_ASC, 'inputType' => 'text', - 'eval' => ['maxlength' => 128, 'mandatory' => true, 'tl_class' => 'w50'], + 'eval' => [ + 'maxlength' => 128, + 'mandatory' => true, + 'tl_class' => 'w50', + ], 'sql' => "varchar(128) NOT NULL default ''", ], 'htmlId' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['htmlId'], 'search' => true, 'inputType' => 'text', - 'eval' => ['maxlength' => 64, 'tl_class' => 'w50'], + 'eval' => [ + 'maxlength' => 64, + 'tl_class' => 'w50', + ], 'sql' => "varchar(64) NOT NULL default ''", ], // visualization @@ -156,7 +169,11 @@ 'inputType' => 'select', 'options' => GoogleMapListener::TYPES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['tl_class' => 'w50', 'mandatory' => true, 'includeBlankOption' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'mandatory' => true, + 'includeBlankOption' => true, + ], 'sql' => "varchar(64) NOT NULL default '".MapTypeId::ROADMAP."'", ], 'sizeMode' => [ @@ -165,56 +182,93 @@ 'inputType' => 'select', 'options' => GoogleMapListener::SIZE_MODES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['tl_class' => 'w50', 'mandatory' => true, 'includeBlankOption' => true, 'submitOnChange' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'mandatory' => true, + 'includeBlankOption' => true, + 'submitOnChange' => true, + ], 'sql' => "varchar(64) NOT NULL default '".GoogleMapListener::SIZE_MODE_ASPECT_RATIO."'", ], 'width' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['width'], 'inputType' => 'inputUnit', 'options' => ['px', '%', 'em', 'rem'], - 'eval' => ['includeBlankOption' => true, 'rgxp' => 'digit_auto_inherit', 'maxlength' => 20, 'tl_class' => 'w50'], + 'eval' => [ + 'includeBlankOption' => true, + 'rgxp' => 'digit_auto_inherit', + 'maxlength' => 20, + 'tl_class' => 'w50', + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'height' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['height'], 'inputType' => 'inputUnit', 'options' => ['px', '%', 'em', 'rem'], - 'eval' => ['includeBlankOption' => true, 'rgxp' => 'digit_auto_inherit', 'maxlength' => 20, 'tl_class' => 'w50'], + 'eval' => [ + 'includeBlankOption' => true, + 'rgxp' => 'digit_auto_inherit', + 'maxlength' => 20, + 'tl_class' => 'w50', + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'aspectRatioX' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['aspectRatioX'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 5, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 5, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "int(5) unsigned NOT NULL default '16'", ], 'aspectRatioY' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['aspectRatioY'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 5, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 5, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "int(5) unsigned NOT NULL default '9'", ], 'addClusterer' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['addClusterer'], 'filter' => true, 'inputType' => 'checkbox', - 'eval' => ['submitOnChange' => true, 'tl_class' => 'clr m12'], + 'eval' => [ + 'submitOnChange' => true, + 'tl_class' => 'clr m12', + ], 'sql' => "char(1) NOT NULL default ''", ], 'clustererImg' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['clustererImg'], 'search' => true, 'inputType' => 'text', - 'eval' => ['mandatory' => false, 'maxlength' => 255], + 'eval' => [ + 'mandatory' => false, + 'maxlength' => 255, + ], 'sql' => "varchar(255) NOT NULL default ''", ], 'styles' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['styles'], 'search' => true, 'inputType' => 'textarea', - 'eval' => ['allowHtml' => true, 'tl_class' => 'clr', 'class' => 'monospace', 'rte' => 'ace|js', 'helpwizard' => true], + 'eval' => [ + 'allowHtml' => true, + 'tl_class' => 'clr', + 'class' => 'monospace', + 'rte' => 'ace|js', + 'helpwizard' => true, + ], 'explanation' => 'insertTags', 'sql' => 'text NULL', ], @@ -222,39 +276,58 @@ 'disableDoubleClickZoom' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['disableDoubleClickZoom'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50'], + 'eval' => [ + 'tl_class' => 'w50', + ], 'sql' => "char(1) NOT NULL default '1'", ], 'scrollwheel' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['scrollwheel'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50'], + 'eval' => [ + 'tl_class' => 'w50', + ], 'sql' => "char(1) NOT NULL default ''", ], 'draggable' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['draggable'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50'], + 'eval' => [ + 'tl_class' => 'w50', + ], 'sql' => "char(1) NOT NULL default '1'", ], 'staticMapNoscript' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['staticMapNoscript'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50', 'submitOnChange' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'submitOnChange' => true, + ], 'sql' => "char(1) NOT NULL default '1'", ], 'staticMapWidth' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['staticMapWidth'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 10, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 10, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "int(10) unsigned NOT NULL default '0'", ], 'staticMapHeight' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['staticMapHeight'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 10, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 10, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "int(10) unsigned NOT NULL default '0'", ], // positioning @@ -264,7 +337,12 @@ 'inputType' => 'select', 'options' => GoogleMapListener::POSITIONING_MODES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['tl_class' => 'w50', 'mandatory' => true, 'includeBlankOption' => true, 'submitOnChange' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'mandatory' => true, + 'includeBlankOption' => true, + 'submitOnChange' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'boundMode' => [ @@ -273,35 +351,60 @@ 'inputType' => 'select', 'options' => GoogleMapListener::BOUND_MODES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['tl_class' => 'w50', 'mandatory' => true, 'includeBlankOption' => true, 'submitOnChange' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'mandatory' => true, + 'includeBlankOption' => true, + 'submitOnChange' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'boundNorthEastLat' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['boundNorthEastLat'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 16, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 16, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "decimal(8,6) NOT NULL default '0.000000'", ], 'boundNorthEastLng' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['boundNorthEastLng'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 16, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 16, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "decimal(9,6) NOT NULL default '0.000000'", ], 'boundSouthWestLat' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['boundSouthWestLat'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 16, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 16, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "decimal(8,6) NOT NULL default '0.000000'", ], 'boundSouthWestLng' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['boundSouthWestLng'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 16, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 16, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "decimal(9,6) NOT NULL default '0.000000'", ], 'centerMode' => [ @@ -310,21 +413,36 @@ 'inputType' => 'select', 'options' => GoogleMapListener::CENTER_MODES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['tl_class' => 'w50', 'mandatory' => true, 'includeBlankOption' => true, 'submitOnChange' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'mandatory' => true, + 'includeBlankOption' => true, + 'submitOnChange' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'centerLat' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['centerLat'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 16, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 16, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "decimal(8,6) NOT NULL default '0.000000'", ], 'centerLng' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['centerLng'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 16, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 16, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => [ 'type' => 'decimal', 'precision' => 9, @@ -337,14 +455,23 @@ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['centerAddress'], 'search' => true, 'inputType' => 'text', - 'eval' => ['maxlength' => 255, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'maxlength' => 255, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "varchar(255) NOT NULL default ''", ], 'zoom' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['zoom'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 2, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 2, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "int(2) unsigned NOT NULL default '15'", ], // controls @@ -353,13 +480,20 @@ 'inputType' => 'checkbox', 'options' => GoogleMapListener::TYPES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['mandatory' => true, 'multiple' => true, 'tl_class' => 'w50 autoheight'], + 'eval' => [ + 'mandatory' => true, + 'multiple' => true, + 'tl_class' => 'w50 autoheight', + ], 'sql' => "varchar(255) NOT NULL default '".serialize(GoogleMapListener::TYPES)."'", ], 'addMapTypeControl' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['addMapTypeControl'], 'inputType' => 'checkbox', - 'eval' => ['submitOnChange' => true, 'tl_class' => 'w50 clr'], + 'eval' => [ + 'submitOnChange' => true, + 'tl_class' => 'w50 clr', + ], 'sql' => "char(1) NOT NULL default '1'", ], 'mapTypeControlStyle' => [ @@ -367,7 +501,10 @@ 'inputType' => 'select', 'options' => GoogleMapListener::MAP_CONTROL_STYLES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['mandatory' => true, 'tl_class' => 'w50'], + 'eval' => [ + 'mandatory' => true, + 'tl_class' => 'w50', + ], 'sql' => "varchar(16) NOT NULL default 'default'", ], 'mapTypeControlPos' => [ @@ -375,13 +512,19 @@ 'inputType' => 'radioTable', 'options' => GoogleMapListener::POSITIONS, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['cols' => 3, 'tl_class' => 'google-maps-bundle w50 autoheight'], + 'eval' => [ + 'cols' => 3, + 'tl_class' => 'google-maps-bundle w50 autoheight', + ], 'sql' => "varchar(16) NOT NULL default 'top_right'", ], 'addZoomControl' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['addZoomControl'], 'inputType' => 'checkbox', - 'eval' => ['submitOnChange' => true, 'tl_class' => 'w50 clr'], + 'eval' => [ + 'submitOnChange' => true, + 'tl_class' => 'w50 clr', + ], 'sql' => "char(1) NOT NULL default '1'", ], 'zoomControlPos' => [ @@ -389,13 +532,19 @@ 'inputType' => 'radioTable', 'options' => GoogleMapListener::POSITIONS, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['cols' => 3, 'tl_class' => 'google-maps-bundle w50 autoheight'], + 'eval' => [ + 'cols' => 3, + 'tl_class' => 'google-maps-bundle w50 autoheight', + ], 'sql' => "varchar(16) NOT NULL default 'top_left'", ], 'addRotateControl' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['addRotateControl'], 'inputType' => 'checkbox', - 'eval' => ['submitOnChange' => true, 'tl_class' => 'w50 clr'], + 'eval' => [ + 'submitOnChange' => true, + 'tl_class' => 'w50 clr', + ], 'sql' => "char(1) NOT NULL default '1'", ], 'rotateControlPos' => [ @@ -403,13 +552,19 @@ 'inputType' => 'radioTable', 'options' => GoogleMapListener::POSITIONS, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['cols' => 3, 'tl_class' => 'google-maps-bundle w50 autoheight'], + 'eval' => [ + 'cols' => 3, + 'tl_class' => 'google-maps-bundle w50 autoheight', + ], 'sql' => "varchar(16) NOT NULL default 'top_left'", ], 'addFullscreenControl' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['addFullscreenControl'], 'inputType' => 'checkbox', - 'eval' => ['submitOnChange' => true, 'tl_class' => 'w50 clr'], + 'eval' => [ + 'submitOnChange' => true, + 'tl_class' => 'w50 clr', + ], 'sql' => "char(1) NOT NULL default '1'", ], 'fullscreenControlPos' => [ @@ -417,13 +572,19 @@ 'inputType' => 'radioTable', 'options' => GoogleMapListener::POSITIONS, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['cols' => 3, 'tl_class' => 'google-maps-bundle w50 autoheight'], + 'eval' => [ + 'cols' => 3, + 'tl_class' => 'google-maps-bundle w50 autoheight', + ], 'sql' => "varchar(16) NOT NULL default 'top_left'", ], 'addStreetViewControl' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['addStreetViewControl'], 'inputType' => 'checkbox', - 'eval' => ['submitOnChange' => true, 'tl_class' => 'w50 clr'], + 'eval' => [ + 'submitOnChange' => true, + 'tl_class' => 'w50 clr', + ], 'sql' => "char(1) NOT NULL default '1'", ], 'streetViewControlPos' => [ @@ -431,13 +592,18 @@ 'inputType' => 'radioTable', 'options' => GoogleMapListener::POSITIONS, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map']['reference'], - 'eval' => ['cols' => 3, 'tl_class' => 'google-maps-bundle w50 autoheight'], + 'eval' => [ + 'cols' => 3, + 'tl_class' => 'google-maps-bundle w50 autoheight', + ], 'sql' => "varchar(16) NOT NULL default 'top_left'", ], 'addScaleControl' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['addScaleControl'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50 clr'], + 'eval' => [ + 'tl_class' => 'w50 clr', + ], 'sql' => "char(1) NOT NULL default '1'", ], 'responsive' => [ @@ -475,21 +641,34 @@ 'filter' => true, 'inputType' => 'select', 'options_callback' => static fn () => Controller::getTemplateGroup('gmap_map_'), - 'eval' => ['tl_class' => 'w50', 'includeBlankOption' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'includeBlankOption' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'overrideLanguage' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['overrideLanguage'], 'filter' => true, 'inputType' => 'checkbox', - 'eval' => ['doNotCopy' => true, 'submitOnChange' => true], + 'eval' => [ + 'doNotCopy' => true, + 'submitOnChange' => true, + ], 'sql' => "char(1) NOT NULL default ''", ], 'language' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map']['language'], 'search' => true, 'inputType' => 'text', - 'eval' => ['mandatory' => true, 'rgxp' => 'language', 'maxlength' => 5, 'nospace' => true, 'doNotCopy' => true, 'tl_class' => 'w50'], + 'eval' => [ + 'mandatory' => true, + 'rgxp' => 'language', + 'maxlength' => 5, + 'nospace' => true, + 'doNotCopy' => true, + 'tl_class' => 'w50', + ], 'sql' => "varchar(5) NOT NULL default ''", ], ], diff --git a/contao/dca/tl_google_map_overlay.php b/contao/dca/tl_google_map_overlay.php index 3cea53b..b157988 100644 --- a/contao/dca/tl_google_map_overlay.php +++ b/contao/dca/tl_google_map_overlay.php @@ -36,7 +36,7 @@ 'format' => '%s', ], 'sorting' => [ - 'mode' => 4, + 'mode' => DataContainer::MODE_PARENT, 'fields' => ['type', 'title'], 'headerFields' => ['title'], 'panelLayout' => 'filter;sort,search,limit', @@ -87,7 +87,10 @@ 'pid' => [ 'foreignKey' => 'tl_google_map.title', 'sql' => "int(10) unsigned NOT NULL default '0'", - 'relation' => ['type' => 'belongsTo', 'load' => 'eager'], + 'relation' => [ + 'type' => 'belongsTo', + 'load' => 'eager', + ], ], 'tstamp' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['tstamp'], @@ -98,9 +101,12 @@ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['title'], 'search' => true, 'sorting' => true, - 'flag' => 1, + 'flag' => DataContainer::SORT_INITIAL_LETTER_ASC, 'inputType' => 'text', - 'eval' => ['mandatory' => true, 'tl_class' => 'w50'], + 'eval' => [ + 'mandatory' => true, + 'tl_class' => 'w50', + ], 'sql' => "varchar(255) NOT NULL default ''", ], 'type' => [ @@ -109,7 +115,12 @@ 'inputType' => 'select', 'options' => OverlayListener::TYPES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['reference'], - 'eval' => ['tl_class' => 'w50', 'mandatory' => true, 'includeBlankOption' => true, 'submitOnChange' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'mandatory' => true, + 'includeBlankOption' => true, + 'submitOnChange' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], // config @@ -119,14 +130,22 @@ 'inputType' => 'select', 'options' => OverlayListener::TITLE_MODES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['reference'], - 'eval' => ['tl_class' => 'w50', 'includeBlankOption' => true, 'submitOnChange' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'includeBlankOption' => true, + 'submitOnChange' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'titleText' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['titleText'], 'search' => true, 'inputType' => 'text', - 'eval' => ['maxlength' => 255, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'maxlength' => 255, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "varchar(255) NOT NULL default ''", ], 'positioningMode' => [ @@ -135,28 +154,47 @@ 'inputType' => 'select', 'options' => OverlayListener::POSITIONING_MODES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['reference'], - 'eval' => ['tl_class' => 'w50 clr', 'mandatory' => true, 'includeBlankOption' => true, 'submitOnChange' => true], + 'eval' => [ + 'tl_class' => 'w50 clr', + 'mandatory' => true, + 'includeBlankOption' => true, + 'submitOnChange' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'positioningLat' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['positioningLat'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 16, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 16, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "decimal(8,6) NOT NULL default '0.000000'", ], 'positioningLng' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['positioningLng'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 16, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 16, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "decimal(9,6) NOT NULL default '0.000000'", ], 'positioningAddress' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['positioningAddress'], 'search' => true, 'inputType' => 'text', - 'eval' => ['maxlength' => 255, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'maxlength' => 255, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "varchar(255) NOT NULL default ''", ], 'animation' => [ @@ -165,7 +203,10 @@ 'inputType' => 'select', 'options' => OverlayListener::ANIMATIONS, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['reference'], - 'eval' => ['tl_class' => 'w50', 'includeBlankOption' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'includeBlankOption' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'markerType' => [ @@ -174,47 +215,84 @@ 'inputType' => 'select', 'options' => OverlayListener::MARKER_TYPES, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['reference'], - 'eval' => ['tl_class' => 'w50 clr', 'mandatory' => true, 'includeBlankOption' => true, 'submitOnChange' => true], + 'eval' => [ + 'tl_class' => 'w50 clr', + 'mandatory' => true, + 'includeBlankOption' => true, + 'submitOnChange' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'fillColor' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['fillColor'], 'inputType' => 'text', - 'eval' => ['maxlength' => 6, 'isHexColor' => true, 'colorpicker' => true, 'decodeEntities' => true, 'tl_class' => 'w50 wizard'], + 'eval' => [ + 'maxlength' => 6, + 'isHexColor' => true, + 'colorpicker' => true, + 'decodeEntities' => true, + 'tl_class' => 'w50 wizard', + ], 'sql' => "varchar(6) NOT NULL default ''", ], 'iconSrc' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['iconSrc'], 'inputType' => 'fileTree', - 'eval' => ['fieldType' => 'radio', 'filesOnly' => true, 'extensions' => 'gif,jpg,jpeg,png', 'mandatory' => true, 'tl_class' => 'clr'], + 'eval' => [ + 'fieldType' => 'radio', + 'filesOnly' => true, + 'extensions' => 'gif,jpg,jpeg,png', + 'mandatory' => true, + 'tl_class' => 'clr', + ], 'sql' => 'binary(16) NULL', ], 'iconWidth' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['iconWidth'], 'inputType' => 'inputUnit', 'options' => ['px', '%', 'em', 'rem'], - 'eval' => ['rgxp' => 'digit', 'maxlength' => 10, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 10, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'iconHeight' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['iconHeight'], 'inputType' => 'inputUnit', 'options' => ['px', '%', 'em', 'rem'], - 'eval' => ['rgxp' => 'digit', 'maxlength' => 10, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 10, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'iconAnchorX' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['iconAnchorX'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 5, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 5, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "int(5) unsigned NOT NULL default '0'", ], 'iconAnchorY' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['iconAnchorY'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 5, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 5, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "int(5) unsigned NOT NULL default '0'", ], 'clickEvent' => [ @@ -223,28 +301,42 @@ 'inputType' => 'select', 'options' => OverlayListener::CLICK_EVENTS, 'reference' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['reference'], - 'eval' => ['includeBlankOption' => true, 'submitOnChange' => true, 'tl_class' => 'w50 clr'], + 'eval' => [ + 'includeBlankOption' => true, + 'submitOnChange' => true, + 'tl_class' => 'w50 clr', + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'infoWindowText' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['infoWindowText'], 'search' => true, 'inputType' => 'textarea', - 'eval' => ['rte' => 'tinyMCE', 'helpwizard' => true, 'tl_class' => 'long clr'], + 'eval' => [ + 'rte' => 'tinyMCE', + 'helpwizard' => true, + 'tl_class' => 'long clr', + ], 'explanation' => 'insertTags', 'sql' => 'text NULL', ], 'addRouting' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['addRouting'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50', 'submitOnChange' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'submitOnChange' => true, + ], 'sql' => "char(1) NOT NULL default ''", ], 'routingAddress' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['routingAddress'], 'search' => true, 'inputType' => 'text', - 'eval' => ['maxlength' => 255, 'tl_class' => 'long clr'], + 'eval' => [ + 'maxlength' => 255, + 'tl_class' => 'long clr', + ], 'sql' => "varchar(255) NOT NULL default ''", ], 'routingTemplate' => [ @@ -252,69 +344,106 @@ 'filter' => true, 'inputType' => 'select', 'options_callback' => static fn () => Controller::getTemplateGroup('gmap_routing_'), - 'eval' => ['tl_class' => 'w50', 'includeBlankOption' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'includeBlankOption' => true, + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'infoWindowWidth' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['infoWindowWidth'], 'inputType' => 'inputUnit', 'options' => ['px', '%', 'em', 'rem'], - 'eval' => ['tl_class' => 'w50'], + 'eval' => [ + 'tl_class' => 'w50', + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'infoWindowHeight' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['infoWindowHeight'], 'inputType' => 'inputUnit', 'options' => ['px', '%', 'em', 'rem'], - 'eval' => ['tl_class' => 'w50'], + 'eval' => [ + 'tl_class' => 'w50', + ], 'sql' => "varchar(64) NOT NULL default ''", ], 'infoWindowAnchorX' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['infoWindowAnchorX'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 10, 'tl_class' => 'w50'], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 10, + 'tl_class' => 'w50', + ], 'sql' => "int(10) unsigned NOT NULL default '0'", ], 'infoWindowAnchorY' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['infoWindowAnchorY'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 10, 'tl_class' => 'w50'], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 10, + 'tl_class' => 'w50', + ], 'sql' => "int(10) unsigned NOT NULL default '0'", ], 'url' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['url'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'url', 'decodeEntities' => true, 'maxlength' => 255, 'tl_class' => 'w50 wizard', 'mandatory' => true, 'dcaPicker' => true], + 'eval' => [ + 'rgxp' => 'url', + 'decodeEntities' => true, + 'maxlength' => 255, + 'tl_class' => 'w50 wizard', + 'mandatory' => true, + 'dcaPicker' => true, + ], 'sql' => "varchar(255) NOT NULL default ''", ], 'target' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['target'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50 m12'], + 'eval' => [ + 'tl_class' => 'w50 m12', + ], 'sql' => "char(1) NOT NULL default ''", ], 'zIndex' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['zIndex'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'digit', 'maxlength' => 10, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'digit', + 'maxlength' => 10, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "int(10) unsigned NOT NULL default '0'", ], 'kmlUrl' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['kmlUrl'], 'search' => true, 'inputType' => 'text', - 'eval' => ['rgxp' => 'url', 'decodeEntities' => true, 'maxlength' => 255, 'tl_class' => 'w50', 'mandatory' => true], + 'eval' => [ + 'rgxp' => 'url', + 'decodeEntities' => true, + 'maxlength' => 255, + 'tl_class' => 'w50', + 'mandatory' => true, + ], 'sql' => "varchar(255) NOT NULL default ''", ], 'kmlClickable' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['kmlClickable'], 'filter' => true, 'default' => true, - 'eval' => ['tl_class' => 'clr m12'], + 'eval' => [ + 'tl_class' => 'clr m12', + ], 'inputType' => 'checkbox', 'sql' => "char(1) NOT NULL default '1'", ], @@ -322,7 +451,9 @@ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['kmlPreserveViewport'], 'filter' => true, 'default' => false, - 'eval' => ['tl_class' => 'm12'], + 'eval' => [ + 'tl_class' => 'm12', + ], 'inputType' => 'checkbox', 'sql' => "char(1) NOT NULL default ''", ], @@ -330,7 +461,9 @@ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['kmlScreenOverlays'], 'filter' => true, 'default' => true, - 'eval' => ['tl_class' => 'm12'], + 'eval' => [ + 'tl_class' => 'm12', + ], 'inputType' => 'checkbox', 'sql' => "char(1) NOT NULL default '1'", ], @@ -339,7 +472,9 @@ 'filter' => true, 'default' => false, 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'm12'], + 'eval' => [ + 'tl_class' => 'm12', + ], 'sql' => "char(1) NOT NULL default ''", ], 'pathCoordinates' => [ @@ -347,10 +482,14 @@ 'palette' => ['positioningLat', 'positioningLng'], 'fields' => [ '&positioningLat' => [ - 'eval' => ['mandatory' => true], + 'eval' => [ + 'mandatory' => true, + ], ], '&positioningLng' => [ - 'eval' => ['mandatory' => true], + 'eval' => [ + 'mandatory' => true, + ], ], ], 'min' => 3, @@ -362,22 +501,37 @@ ], 'strokeWeight' => [ 'inputType' => 'text', - 'eval' => ['maxlength' => 3, 'tl_class' => 'w50'], + 'eval' => [ + 'maxlength' => 3, + 'tl_class' => 'w50', + ], 'sql' => "varchar(3) NOT NULL default '2'", ], 'strokeColor' => [ 'inputType' => 'text', - 'eval' => ['maxlength' => 6, 'isHexColor' => true, 'colorpicker' => true, 'decodeEntities' => true, 'tl_class' => 'w50 wizard'], + 'eval' => [ + 'maxlength' => 6, + 'isHexColor' => true, + 'colorpicker' => true, + 'decodeEntities' => true, + 'tl_class' => 'w50 wizard', + ], 'sql' => "varchar(6) NOT NULL default ''", ], 'strokeOpacity' => [ 'inputType' => 'text', - 'eval' => ['maxlength' => 3, 'tl_class' => 'w50'], + 'eval' => [ + 'maxlength' => 3, + 'tl_class' => 'w50', + ], 'sql' => "varchar(3) NOT NULL DEFAULT '1.0'", ], 'fillOpacity' => [ 'inputType' => 'text', - 'eval' => ['maxlength' => 3, 'tl_class' => 'w50'], + 'eval' => [ + 'maxlength' => 3, + 'tl_class' => 'w50', + ], 'sql' => "varchar(3) NOT NULL DEFAULT '0.6'", ], // publish @@ -386,19 +540,30 @@ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['published'], 'filter' => true, 'inputType' => 'checkbox', - 'eval' => ['doNotCopy' => true, 'submitOnChange' => true], + 'eval' => [ + 'doNotCopy' => true, + 'submitOnChange' => true, + ], 'sql' => "char(1) NOT NULL default ''", ], 'start' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['start'], 'inputType' => 'text', - 'eval' => ['rgxp' => 'datim', 'datepicker' => true, 'tl_class' => 'w50 wizard'], + 'eval' => [ + 'rgxp' => 'datim', + 'datepicker' => true, + 'tl_class' => 'w50 wizard', + ], 'sql' => "varchar(10) NOT NULL default ''", ], 'stop' => [ 'label' => &$GLOBALS['TL_LANG']['tl_google_map_overlay']['stop'], 'inputType' => 'text', - 'eval' => ['rgxp' => 'datim', 'datepicker' => true, 'tl_class' => 'w50 wizard'], + 'eval' => [ + 'rgxp' => 'datim', + 'datepicker' => true, + 'tl_class' => 'w50 wizard', + ], 'sql' => "varchar(10) NOT NULL default ''", ], ], diff --git a/contao/dca/tl_module.php b/contao/dca/tl_module.php index 9a87f66..bcff3f4 100644 --- a/contao/dca/tl_module.php +++ b/contao/dca/tl_module.php @@ -16,7 +16,7 @@ * Palettes */ $dca['palettes'][ModuleListener::MODULE_GOOGLE_MAP] = - '{type_legend},name,headline,type;{config_legend},googlemaps_map,googlemaps_skipHtml,googlemaps_skipCss,googlemaps_skipJs;{template_legend:hide},customTpl;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID;'; + '{type_legend},name,headline,type;{config_legend},googlemaps_map,googlemaps_skipHtml,googlemaps_skipCss,googlemaps_skipJs;{template_legend:collapsed},customTpl;{protected_legend:collapsed},protected;{expert_legend:collapsed},guests,cssID;'; /** * Fields. @@ -27,26 +27,37 @@ 'filter' => true, 'inputType' => 'select', 'options_callback' => ['huh.google_maps.data_container.google_map', 'getMapChoices'], - 'eval' => ['tl_class' => 'w50', 'mandatory' => true, 'includeBlankOption' => true, 'chosen' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'mandatory' => true, + 'includeBlankOption' => true, + 'chosen' => true, + ], 'sql' => "int(10) unsigned NOT NULL default '0'", 'wizard' => [['huh.google_maps.data_container.map_wizard', 'addWizard']], ], 'googlemaps_skipHtml' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['googlemaps_skipHtml'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50 clr'], + 'eval' => [ + 'tl_class' => 'w50 clr', + ], 'sql' => "char(1) NOT NULL default ''", ], 'googlemaps_skipCss' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['googlemaps_skipCss'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50'], + 'eval' => [ + 'tl_class' => 'w50', + ], 'sql' => "char(1) NOT NULL default ''", ], 'googlemaps_skipJs' => [ 'label' => &$GLOBALS['TL_LANG']['tl_content']['googlemaps_skipJs'], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50'], + 'eval' => [ + 'tl_class' => 'w50', + ], 'sql' => "char(1) NOT NULL default ''", ], ]; diff --git a/contao/dca/tl_settings.php b/contao/dca/tl_settings.php index 2f8f756..d9eaa06 100644 --- a/contao/dca/tl_settings.php +++ b/contao/dca/tl_settings.php @@ -23,13 +23,19 @@ 'label' => &$GLOBALS['TL_LANG']['tl_settings']['googlemaps_apiKey'], 'search' => true, 'inputType' => 'text', - 'eval' => ['maxlength' => 255, 'tl_class' => 'w50'], + 'eval' => [ + 'maxlength' => 255, + 'tl_class' => 'w50', + ], ], 'utilsGoogleApiKey' => [ 'label' => &$GLOBALS['TL_LANG']['tl_settings']['utilsGoogleApiKey'], 'search' => true, 'inputType' => 'text', - 'eval' => ['maxlength' => 255, 'tl_class' => 'w50'], + 'eval' => [ + 'maxlength' => 255, + 'tl_class' => 'w50', + ], ], ]; diff --git a/contao/dca/tl_user.php b/contao/dca/tl_user.php index 389d535..13feb8a 100644 --- a/contao/dca/tl_user.php +++ b/contao/dca/tl_user.php @@ -29,7 +29,9 @@ $dca['fields']['contao_google_maps_bundles'] = [ 'inputType' => 'checkbox', 'foreignKey' => 'tl_google_map.title', - 'eval' => ['multiple' => true], + 'eval' => [ + 'multiple' => true, + ], 'sql' => 'blob NULL', ]; @@ -37,6 +39,8 @@ 'inputType' => 'checkbox', 'options' => ['create', 'delete'], 'reference' => &$GLOBALS['TL_LANG']['MSC'], - 'eval' => ['multiple' => true], + 'eval' => [ + 'multiple' => true, + ], 'sql' => 'blob NULL', ]; diff --git a/contao/dca/tl_user_group.php b/contao/dca/tl_user_group.php index 9ce4654..2e1a428 100644 --- a/contao/dca/tl_user_group.php +++ b/contao/dca/tl_user_group.php @@ -28,7 +28,9 @@ $dca['fields']['contao_google_maps_bundles'] = [ 'inputType' => 'checkbox', 'foreignKey' => 'tl_google_map.title', - 'eval' => ['multiple' => true], + 'eval' => [ + 'multiple' => true, + ], 'sql' => 'blob NULL', ]; @@ -36,6 +38,8 @@ 'inputType' => 'checkbox', 'options' => ['create', 'delete'], 'reference' => &$GLOBALS['TL_LANG']['MSC'], - 'eval' => ['multiple' => true], + 'eval' => [ + 'multiple' => true, + ], 'sql' => 'blob NULL', ]; diff --git a/ecs.php b/ecs.php index 26c52ce..900c88c 100644 --- a/ecs.php +++ b/ecs.php @@ -2,31 +2,37 @@ declare(strict_types=1); -use Contao\EasyCodingStandard\Fixer\TypeHintOrderFixer; -use PhpCsFixer\Fixer\Comment\HeaderCommentFixer; +use PhpCsFixer\Fixer\Basic\BracesPositionFixer; +use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer; +use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer; use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer; -use SlevomatCodingStandard\Sniffs\TypeHints\DisallowArrayTypeHintSyntaxSniff; use Symplify\EasyCodingStandard\Config\ECSConfig; -return static function (ECSConfig $ecsConfig): void { - $ecsConfig->sets([__DIR__.'/tools/ecs/vendor/contao/easy-coding-standard/config/contao.php']); +return ECSConfig::configure() + ->withPaths([ + __DIR__ . '/src', + __DIR__ . '/contao', + ]) - $date = date('Y'); - $ecsConfig->skip([ + // 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', - '*/Resources/config/*.php', + 'src/*Bundle.php' ], - TypeHintOrderFixer::class, - DisallowArrayTypeHintSyntaxSniff::class => ['*Model.php'], - '*/templates/*.html5', - ]); - - $ecsConfig->ruleWithConfiguration(HeaderCommentFixer::class, [ - 'header' => "Copyright (c) $date Heimrich & Hannot GmbH\n\n@license LGPL-3.0-or-later", ]); - - $ecsConfig->parallel(); - $ecsConfig->lineEnding("\n"); - $ecsConfig->cacheDirectory(sys_get_temp_dir().'/ecs_default_cache'); -}; diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..6718826 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,14 @@ +parameters: + level: 1 + paths: + - src + - contao +# universalObjectCratesClasses: +# - Contao\Database\Result +# - Contao\Model +# - Contao\Template + ignoreErrors: + - '#^Call to static method findByPk\(\) on an unknown class Oveleon\\ContaoCookiebar\\Model\\CookieModel\.$#' + - '#^Parameter \$configModel of method HeimrichHannot\\GoogleMapsBundle\\EventListener\\OveleonContaoCookiebarListener\:\:parseHtml\(\) has invalid type Oveleon\\ContaoCookiebar\\Model\\CookieModel\.$#' +includes: + - vendor/phpstan/phpstan-symfony/extension.neon diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..ad391a4 --- /dev/null +++ b/rector.php @@ -0,0 +1,46 @@ +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_81, + ContaoLevelSetList::UP_TO_CONTAO_53, + ContaoSetList::FQCN, + ContaoSetList::ANNOTATIONS_TO_ATTRIBUTES, + ]) + ->withSkip([ + ArrayToFirstClassCallableRector::class, + ]) +; diff --git a/src/Collection/MapCollection.php b/src/Collection/MapCollection.php index 94e7454..2ca8d5b 100644 --- a/src/Collection/MapCollection.php +++ b/src/Collection/MapCollection.php @@ -24,7 +24,10 @@ class MapCollection public function addMap(Map $map, ?int $mapConfigId): void { - $this->maps[] = ['map' => $map, 'id' => $mapConfigId]; + $this->maps[] = [ + 'map' => $map, + 'id' => $mapConfigId, + ]; } /** diff --git a/src/Command/MigrateDlhCommand.php b/src/Command/MigrateDlhCommand.php index aff5ac3..cf7183d 100644 --- a/src/Command/MigrateDlhCommand.php +++ b/src/Command/MigrateDlhCommand.php @@ -25,6 +25,7 @@ use HeimrichHannot\GoogleMapsBundle\EventListener\DataContainer\OverlayListener; use HeimrichHannot\GoogleMapsBundle\Model\GoogleMapModel; use HeimrichHannot\GoogleMapsBundle\Model\OverlayModel; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\InputInterface; @@ -33,12 +34,12 @@ use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +#[AsCommand( + name: 'huh:google-maps:migrate-dlh', + description: 'Migrates existing Maps created using delahaye/dlh_googlemaps.' +)] class MigrateDlhCommand extends Command { - protected static $defaultName = 'huh:google-maps:migrate-dlh'; - - protected static $defaultDescription = 'Migrates existing Maps created using delahaye/dlh_googlemaps.'; - protected bool $dryRun = false; protected array $mapMapper = []; @@ -49,24 +50,17 @@ class MigrateDlhCommand extends Command private bool $cleanBeforeMigration; - private EventDispatcherInterface $dispatcher; - - private ContaoFramework $framework; - - private Connection $connection; - - public function __construct(ContaoFramework $framework, EventDispatcherInterface $eventDispatcher, Connection $connection) - { + public function __construct( + private readonly ContaoFramework $framework, + private readonly EventDispatcherInterface $dispatcher, + private readonly Connection $connection, + ) { parent::__construct(); - $this->framework = $framework; - $this->dispatcher = $eventDispatcher; - $this->connection = $connection; } protected function configure(): void { $this - ->setDescription(static::$defaultDescription) ->addOption('skip-unsupported-field-warnings', null, InputOption::VALUE_NONE, 'Skip warnings indicating that fields don\'t exist anymore in Google Maps v3.') ->addOption('skip-contentelements', null, InputOption::VALUE_NONE, 'Skip migration of content elements.') ->addOption('skip-frontendmodules', null, InputOption::VALUE_NONE, 'Skip migration of frontend modules.') @@ -118,7 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->io->success('dlh_googlemaps migration finished'); - return 0; + return Command::SUCCESS; } protected function migrateApiKeys(): void @@ -255,7 +249,7 @@ protected function migrateMaps(): void $legacyValue = $legacyMap->{$legacyField}; if (\in_array($legacyField, $fieldsToLower, true)) { - $legacyValue = strtolower($legacyValue); + $legacyValue = strtolower((string) $legacyValue); } if (\in_array($legacyField, array_keys($fieldsMappings), true)) { @@ -285,8 +279,8 @@ protected function migrateMaps(): void } else { $map->centerMode = GoogleMapListener::CENTER_MODE_COORDINATE; - if (strpos($legacyMap->center, ',')) { - $coordinates = explode(',', $legacyMap->center); + if (strpos((string) $legacyMap->center, ',')) { + $coordinates = explode(',', (string) $legacyMap->center); if (\is_array($coordinates) && \count($coordinates) > 1) { $map->centerLat = $coordinates[0]; @@ -302,12 +296,12 @@ protected function migrateMaps(): void $map->sizeMode = GoogleMapListener::SIZE_MODE_STATIC; $map->width = serialize([ - 'value' => preg_replace('/[^\d]/i', '', $mapSize[0]), + 'value' => preg_replace('/[^\d]/i', '', (string) $mapSize[0]), 'unit' => 'px', ]); $map->height = serialize([ - 'value' => preg_replace('/[^\d]/i', '', $mapSize[1]), + 'value' => preg_replace('/[^\d]/i', '', (string) $mapSize[1]), 'unit' => 'px', ]); } else { @@ -413,7 +407,7 @@ protected function migrateOverlays(object $legacyMap, GoogleMapModel $map): void $legacyValue = $legacyOverlay->{$legacyField}; if (\in_array($legacyField, $fieldsToLower, true)) { - $legacyValue = strtolower($legacyValue); + $legacyValue = strtolower((string) $legacyValue); } if (\in_array($legacyField, array_keys($fieldsMappings), true)) { @@ -447,7 +441,7 @@ protected function migrateOverlays(object $legacyMap, GoogleMapModel $map): void if ($legacyOverlay->singleCoords) { $overlay->positioningMode = OverlayListener::POSITIONING_MODE_COORDINATE; - if (strpos($legacyOverlay->singleCoords, ',')) { + if (strpos((string) $legacyOverlay->singleCoords, ',')) { $coordinates = explode(',', str_replace(' ', '', $legacyOverlay->singleCoords)); if (\is_array($coordinates) && \count($coordinates) > 1) { @@ -471,8 +465,14 @@ protected function migrateOverlays(object $legacyMap, GoogleMapModel $map): void case OverlayListener::MARKER_TYPE_ICON: $iconSize = StringUtil::deserialize($legacyOverlay->iconSize, true); - $overlay->iconWidth = ['value' => $iconSize[0], 'unit' => 'px']; - $overlay->iconHeight = ['value' => $iconSize[1], 'unit' => 'px']; + $overlay->iconWidth = [ + 'value' => $iconSize[0], + 'unit' => 'px', + ]; + $overlay->iconHeight = [ + 'value' => $iconSize[1], + 'unit' => 'px', + ]; $iconAnchor = StringUtil::deserialize($legacyOverlay->iconAnchor, true); diff --git a/src/Controller/ContentElement/GoogleMapsElementController.php b/src/Controller/ContentElement/GoogleMapsElementController.php index 822bbc2..8ab01d3 100644 --- a/src/Controller/ContentElement/GoogleMapsElementController.php +++ b/src/Controller/ContentElement/GoogleMapsElementController.php @@ -27,17 +27,11 @@ class GoogleMapsElementController extends AbstractContentElementController { public const TYPE = 'google_map'; - protected MapManager $mapManager; - - private ScopeMatcher $scopeMatcher; - - private Utils $utils; - - public function __construct(ScopeMatcher $scopeMatcher, Utils $utils, MapManager $mapManager) - { - $this->scopeMatcher = $scopeMatcher; - $this->utils = $utils; - $this->mapManager = $mapManager; + public function __construct( + private readonly ScopeMatcher $scopeMatcher, + private readonly Utils $utils, + protected MapManager $mapManager, + ) { } protected function getResponse(FragmentTemplate $template, ContentModel $model, Request $request): Response @@ -57,7 +51,7 @@ protected function getResponse(FragmentTemplate $template, ContentModel $model, protected function getBackendWildcard(FragmentTemplate $template, ContentModel $model): Response { $wilcardTemplate = new BackendTemplate('be_wildcard'); - $wilcardTemplate->wildcard = '### '.mb_strtoupper($GLOBALS['TL_LANG']['CTE'][$model->type][0]).' ###'; + $wilcardTemplate->wildcard = '### '.mb_strtoupper((string) $GLOBALS['TL_LANG']['CTE'][$model->type][0]).' ###'; $wilcardTemplate->title = $template->headline; if (null !== ($map = $this->utils->model()->findModelInstanceByPk('tl_google_map', $model->googlemaps_map))) { diff --git a/src/Controller/FrontendModule/GoogleMapsFrontendModuleController.php b/src/Controller/FrontendModule/GoogleMapsFrontendModuleController.php index 665cd89..f617d18 100644 --- a/src/Controller/FrontendModule/GoogleMapsFrontendModuleController.php +++ b/src/Controller/FrontendModule/GoogleMapsFrontendModuleController.php @@ -24,11 +24,9 @@ class GoogleMapsFrontendModuleController extends AbstractFrontendModuleControlle { public const TYPE = 'google_map'; - protected MapManager $mapManager; - - public function __construct(MapManager $mapManager) - { - $this->mapManager = $mapManager; + public function __construct( + protected MapManager $mapManager, + ) { } /** diff --git a/src/Event/BeforeRenderApiEvent.php b/src/Event/BeforeRenderApiEvent.php index dbd4c74..53b6ccd 100644 --- a/src/Event/BeforeRenderApiEvent.php +++ b/src/Event/BeforeRenderApiEvent.php @@ -18,14 +18,10 @@ class BeforeRenderApiEvent extends Event { private ?string $code = null; - private ApiHelper $apiHelper; - - private ApiEvent $event; - - public function __construct(ApiHelper $apiHelper, ApiEvent $event) - { - $this->apiHelper = $apiHelper; - $this->event = $event; + public function __construct( + private readonly ApiHelper $apiHelper, + private readonly ApiEvent $event, + ) { } public function getCode(): ?string diff --git a/src/Event/BeforeRenderMapEvent.php b/src/Event/BeforeRenderMapEvent.php index 7bdab4e..ed69207 100644 --- a/src/Event/BeforeRenderMapEvent.php +++ b/src/Event/BeforeRenderMapEvent.php @@ -15,15 +15,16 @@ class BeforeRenderMapEvent extends Event { - /** @deprecated Use class FQN instead */ - const NAME = 'huh.maps.before_render_map'; + /** + * @deprecated Use class FQN instead + */ + public const NAME = 'huh.maps.before_render_map'; public function __construct( public string $template, public array $templateData, - public Map $map - ) - { + public Map $map, + ) { } /** diff --git a/src/Event/DlhMigrationModifyMapEvent.php b/src/Event/DlhMigrationModifyMapEvent.php index 0c20c91..f20fa15 100644 --- a/src/Event/DlhMigrationModifyMapEvent.php +++ b/src/Event/DlhMigrationModifyMapEvent.php @@ -15,7 +15,7 @@ class DlhMigrationModifyMapEvent extends Event { - const NAME = 'huh.google_maps.event.dlh_migration_modify_map'; + public const NAME = 'huh.google_maps.event.dlh_migration_modify_map'; /** * @var object diff --git a/src/Event/DlhMigrationModifyOverlayEvent.php b/src/Event/DlhMigrationModifyOverlayEvent.php index 212fb1e..d557cb1 100644 --- a/src/Event/DlhMigrationModifyOverlayEvent.php +++ b/src/Event/DlhMigrationModifyOverlayEvent.php @@ -15,7 +15,7 @@ class DlhMigrationModifyOverlayEvent extends Event { - const NAME = 'huh.google_maps.event.dlh_migration_modify_overlay'; + public const NAME = 'huh.google_maps.event.dlh_migration_modify_overlay'; /** * @var object diff --git a/src/Event/GoogleMapsPrepareExternalItemEvent.php b/src/Event/GoogleMapsPrepareExternalItemEvent.php index 91a012a..42371a6 100644 --- a/src/Event/GoogleMapsPrepareExternalItemEvent.php +++ b/src/Event/GoogleMapsPrepareExternalItemEvent.php @@ -19,9 +19,10 @@ class GoogleMapsPrepareExternalItemEvent extends Event public function __construct( public readonly array $itemData, /** - * The overlay model for the current item. Null if no marker should be added + * The overlay model for the current item. Null if no marker should be added. */ public ?OverlayModel $overlayModel, - public Model|array|null $context = null - ) {} + public Model|array|null $context = null, + ) { + } } diff --git a/src/EventListener/ApiRenderListener.php b/src/EventListener/ApiRenderListener.php index 9a3208d..8fddfed 100644 --- a/src/EventListener/ApiRenderListener.php +++ b/src/EventListener/ApiRenderListener.php @@ -19,17 +19,13 @@ class ApiRenderListener implements EventSubscriberInterface { - private ApiHelper $apiHelper; - - private EventDispatcherInterface $eventDispatcher; - - public function __construct(ApiHelper $apiHelper, EventDispatcherInterface $eventDispatcher) - { - $this->apiHelper = $apiHelper; - $this->eventDispatcher = $eventDispatcher; + public function __construct( + private readonly ApiHelper $apiHelper, + private readonly EventDispatcherInterface $eventDispatcher, + ) { } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ ApiEvents::JAVASCRIPT => [ diff --git a/src/EventListener/ConsentBridgeListener.php b/src/EventListener/ConsentBridgeListener.php index 48e1fd2..4746d71 100644 --- a/src/EventListener/ConsentBridgeListener.php +++ b/src/EventListener/ConsentBridgeListener.php @@ -12,8 +12,8 @@ use Contao\Config; use Contao\CoreBundle\DataContainer\PaletteManipulator; -use Contao\CoreBundle\ServiceAnnotation\Callback; -use Contao\CoreBundle\ServiceAnnotation\Hook; +use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use Contao\DataContainer; use Contao\Template; use HeimrichHannot\GoogleMapsBundle\Util\DcaUtil; @@ -23,34 +23,18 @@ final class ConsentBridgeListener { - /** - * @var ConsentToolManager - */ - private $consentToolManager; - - /** - * @var ConsentIdParser - */ - private $consentIdParser; - - /** - * @var DcaUtil - */ - private $dcaUtil; - - public function __construct(ConsentToolManager $consentManager, ConsentIdParser $consentIdParser, DcaUtil $dcaUtil) - { - $this->consentToolManager = $consentManager; - $this->consentIdParser = $consentIdParser; - $this->dcaUtil = $dcaUtil; + public function __construct( + private readonly ConsentToolManager $consentToolManager, + private readonly ConsentIdParser $consentIdParser, + private readonly DcaUtil $dcaUtil, + ) { } /** * Adjust the data containers for the consent bridge support. High priority * required so that the service tags can be applied. - * - * @Hook("loadDataContainer", priority=255) */ + #[AsHook('loadDataContainer', priority: 255)] public function onLoadDataContainer(string $table): void { if ([] === $this->consentToolManager->consentTools()) { @@ -81,9 +65,7 @@ public function onLoadDataContainer(string $table): void } } - /** - * @Callback(table="tl_settings", target="config.onload") - */ + #[AsCallback(table: 'tl_settings', target: 'config.onload')] public function onLoadSettings(DataContainer $table): void { if ([] === $this->consentToolManager->consentTools()) { @@ -96,9 +78,7 @@ public function onLoadSettings(DataContainer $table): void ; } - /** - * @Callback(table="tl_page", target="config.onload") - */ + #[AsCallback(table: 'tl_page', target: 'config.onload')] public function onLoadPage(DataContainer $table): void { if ([] === $this->consentToolManager->consentTools()) { @@ -112,10 +92,8 @@ public function onLoadPage(DataContainer $table): void ; } - /** - * @Callback(table="tl_settings", target="fields.googlemaps_consentId.options") - * @Callback(table="tl_page", target="fields.googlemaps_consentId.options") - */ + #[AsCallback(table: 'tl_settings', target: 'fields.googlemaps_consentId.options')] + #[AsCallback(table: 'tl_page', target: 'fields.googlemaps_consentId.options')] public function consentIdOptions(): array { /** @var array> $options */ @@ -142,9 +120,8 @@ public function consentIdOptions(): array /** * Adjust the generated map api. Priority -1 ensures it's called after the * ReplaceDynamicScriptTagsListener listener. - * - * @Hook("replaceDynamicScriptTags", priority=-1) */ + #[AsHook('replaceDynamicScriptTags', priority: -1)] public function onReplaceDynamicScriptTags(string $buffer): string { if (!isset($GLOBALS['TL_BODY']['huhGoogleMaps'])) { @@ -165,9 +142,7 @@ public function onReplaceDynamicScriptTags(string $buffer): string return $buffer; } - /** - * @Hook("parseTemplate") - */ + #[AsHook('parseTemplate')] public function onParseTemplate(Template $template): void { if (!preg_match('#^(ce|mod)_google_map#', $template->getName())) { @@ -205,7 +180,9 @@ private function determineConsentId(): ?ConsentId } $consentIdAsString = $this->dcaUtil->getOverridableProperty('googlemaps_consentId', [ - (object) ['googlemaps_consentId' => Config::get('googlemaps_consentId')], + (object) [ + 'googlemaps_consentId' => Config::get('googlemaps_consentId'), + ], ['tl_page', $objPage->rootId ?: $objPage->id], ]); diff --git a/src/EventListener/DataContainer/ContentListener.php b/src/EventListener/DataContainer/ContentListener.php index 6ef91cf..58966d9 100644 --- a/src/EventListener/DataContainer/ContentListener.php +++ b/src/EventListener/DataContainer/ContentListener.php @@ -12,5 +12,5 @@ class ContentListener { - const ELEMENT_GOOGLE_MAP = 'google_map'; + public const ELEMENT_GOOGLE_MAP = 'google_map'; } diff --git a/src/EventListener/DataContainer/GoogleMapListener.php b/src/EventListener/DataContainer/GoogleMapListener.php index d0aa0ff..bb2e381 100644 --- a/src/EventListener/DataContainer/GoogleMapListener.php +++ b/src/EventListener/DataContainer/GoogleMapListener.php @@ -25,60 +25,60 @@ class GoogleMapListener { - const SIZE_MODE_ASPECT_RATIO = 'aspect_ratio'; + public const SIZE_MODE_ASPECT_RATIO = 'aspect_ratio'; - const SIZE_MODE_STATIC = 'static'; + public const SIZE_MODE_STATIC = 'static'; - const SIZE_MODE_CSS = 'css'; + public const SIZE_MODE_CSS = 'css'; - const SIZE_MODES = [ + public const SIZE_MODES = [ self::SIZE_MODE_ASPECT_RATIO, self::SIZE_MODE_STATIC, self::SIZE_MODE_CSS, ]; - const MAP_TYPE_BASE = 'base'; + public const MAP_TYPE_BASE = 'base'; - const MAP_TYPE_RESPONSIVE = 'responsive'; + public const MAP_TYPE_RESPONSIVE = 'responsive'; - const TYPES = [ + public const TYPES = [ MapTypeId::ROADMAP, MapTypeId::SATELLITE, MapTypeId::TERRAIN, MapTypeId::HYBRID, ]; - const POSITIONING_MODE_STANDARD = 'standard'; + public const POSITIONING_MODE_STANDARD = 'standard'; - const POSITIONING_MODE_BOUND = 'bound'; + public const POSITIONING_MODE_BOUND = 'bound'; - const POSITIONING_MODES = [ + public const POSITIONING_MODES = [ self::POSITIONING_MODE_STANDARD, self::POSITIONING_MODE_BOUND, ]; - const BOUND_MODE_COORDINATES = 'coordinates'; + public const BOUND_MODE_COORDINATES = 'coordinates'; - const BOUND_MODE_AUTOMATIC = 'automatic'; + public const BOUND_MODE_AUTOMATIC = 'automatic'; - const BOUND_MODES = [ + public const BOUND_MODES = [ self::BOUND_MODE_COORDINATES, self::BOUND_MODE_AUTOMATIC, ]; - const CENTER_MODE_COORDINATE = 'coordinate'; + public const CENTER_MODE_COORDINATE = 'coordinate'; - const CENTER_MODE_STATIC_ADDRESS = 'static_address'; + public const CENTER_MODE_STATIC_ADDRESS = 'static_address'; - const CENTER_MODE_EXTERNAL = 'external'; + public const CENTER_MODE_EXTERNAL = 'external'; - const CENTER_MODES = [ + public const CENTER_MODES = [ self::CENTER_MODE_COORDINATE, self::CENTER_MODE_STATIC_ADDRESS, self::CENTER_MODE_EXTERNAL, ]; - const POSITIONS = [ + public const POSITIONS = [ ControlPosition::TOP_LEFT, ControlPosition::TOP_CENTER, ControlPosition::TOP_RIGHT, @@ -96,26 +96,18 @@ class GoogleMapListener ControlPosition::BOTTOM_RIGHT, ]; - const MAP_CONTROL_STYLES = [ + public const MAP_CONTROL_STYLES = [ MapTypeControlStyle::DEFAULT_, MapTypeControlStyle::DROPDOWN_MENU, MapTypeControlStyle::HORIZONTAL_BAR, ]; - protected ContaoFramework $framework; - - protected Connection $connection; - - protected Security $security; - - protected RequestStack $requestStack; - - public function __construct(ContaoFramework $framework, Connection $connection, Security $security, RequestStack $requestStack) - { - $this->framework = $framework; - $this->connection = $connection; - $this->security = $security; - $this->requestStack = $requestStack; + public function __construct( + protected ContaoFramework $framework, + protected Connection $connection, + protected Security $security, + protected RequestStack $requestStack, + ) { } public function getResponsiveMaps(DataContainer $dc) @@ -210,7 +202,11 @@ public function adjustPermissions(string|int $insertId): void $mapsAllowed = StringUtil::deserialize($groupPermissions['contao_google_maps_bundles'], true); $mapsAllowed[] = $insertId; - $this->connection->update('tl_user_group', ['contao_google_maps_bundles' => serialize($mapsAllowed)], ['id' => $groupPermissions['id']]); + $this->connection->update('tl_user_group', [ + 'contao_google_maps_bundles' => serialize($mapsAllowed), + ], [ + 'id' => $groupPermissions['id'], + ]); } } } @@ -230,7 +226,11 @@ public function adjustPermissions(string|int $insertId): void $mapsAllowed = StringUtil::deserialize($userPermissions['contao_google_maps_bundles'], true); $mapsAllowed[] = $insertId; - $this->connection->update('tl_user', ['contao_google_maps_bundles' => serialize($mapsAllowed)], ['id' => $userPermissions['id']]); + $this->connection->update('tl_user', [ + 'contao_google_maps_bundles' => serialize($mapsAllowed), + ], [ + 'id' => $userPermissions['id'], + ]); } } diff --git a/src/EventListener/DataContainer/MapWizardListener.php b/src/EventListener/DataContainer/MapWizardListener.php index 2a30675..a4faeb1 100644 --- a/src/EventListener/DataContainer/MapWizardListener.php +++ b/src/EventListener/DataContainer/MapWizardListener.php @@ -25,7 +25,14 @@ public static function addWizard(DataContainer $dc) $label = System::getContainer()->get('translator')->trans('tl_google_map.edit.1', [], 'contao_tl_google_map'); $title = \sprintf($label, $dc->value); - $href = System::getContainer()->get('router')->generate('contao_backend', ['do' => 'google_maps', 'table' => 'tl_google_map', 'act' => 'edit', 'id' => $dc->value, 'popup' => '1', 'nb' => '1']); + $href = System::getContainer()->get('router')->generate('contao_backend', [ + 'do' => 'google_maps', + 'table' => 'tl_google_map', + 'act' => 'edit', + 'id' => $dc->value, + 'popup' => '1', + 'nb' => '1', + ]); return ' '.Image::getHtml('edit.svg', $title).''; } diff --git a/src/EventListener/DataContainer/OverlayListener.php b/src/EventListener/DataContainer/OverlayListener.php index 4ca61de..eee9e73 100644 --- a/src/EventListener/DataContainer/OverlayListener.php +++ b/src/EventListener/DataContainer/OverlayListener.php @@ -22,23 +22,23 @@ class OverlayListener extends Backend { - const TYPE_MARKER = 'marker'; + public const TYPE_MARKER = 'marker'; - const TYPE_INFO_WINDOW = 'infowindow'; + public const TYPE_INFO_WINDOW = 'infowindow'; - const TYPE_POLYLINE = 'polyline'; + public const TYPE_POLYLINE = 'polyline'; - const TYPE_POLYGON = 'polygon'; + public const TYPE_POLYGON = 'polygon'; - const TYPE_CIRCLE = 'circle'; + public const TYPE_CIRCLE = 'circle'; - const TYPE_RECTANGLE = 'rectangle'; + public const TYPE_RECTANGLE = 'rectangle'; - const TYPE_GROUND_OVERLAY = 'ground_overlay'; + public const TYPE_GROUND_OVERLAY = 'ground_overlay'; - const TYPE_KML_LAYER = 'kml'; + public const TYPE_KML_LAYER = 'kml'; - const TYPES = [ + public const TYPES = [ self::TYPE_MARKER, self::TYPE_INFO_WINDOW, self::TYPE_POLYLINE, @@ -49,55 +49,51 @@ class OverlayListener extends Backend self::TYPE_KML_LAYER, ]; - const TITLE_MODE_TITLE_FIELD = 'title_field'; + public const TITLE_MODE_TITLE_FIELD = 'title_field'; - const TITLE_MODE_CUSTOM_TEXT = 'custom_text'; + public const TITLE_MODE_CUSTOM_TEXT = 'custom_text'; - const TITLE_MODES = [ + public const TITLE_MODES = [ self::TITLE_MODE_TITLE_FIELD, self::TITLE_MODE_CUSTOM_TEXT, ]; - const MARKER_TYPE_SIMPLE = 'simple'; + public const MARKER_TYPE_SIMPLE = 'simple'; - const MARKER_TYPE_ICON = 'icon'; + public const MARKER_TYPE_ICON = 'icon'; - const MARKER_TYPES = [ + public const MARKER_TYPES = [ self::MARKER_TYPE_SIMPLE, self::MARKER_TYPE_ICON, ]; - const CLICK_EVENT_LINK = 'link'; + public const CLICK_EVENT_LINK = 'link'; - const CLICK_EVENT_INFO_WINDOW = 'infowindow'; + public const CLICK_EVENT_INFO_WINDOW = 'infowindow'; - const CLICK_EVENTS = [ + public const CLICK_EVENTS = [ self::CLICK_EVENT_LINK, self::CLICK_EVENT_INFO_WINDOW, ]; - const POSITIONING_MODE_COORDINATE = 'coordinate'; + public const POSITIONING_MODE_COORDINATE = 'coordinate'; - const POSITIONING_MODE_STATIC_ADDRESS = 'static_address'; + public const POSITIONING_MODE_STATIC_ADDRESS = 'static_address'; - const POSITIONING_MODES = [ + public const POSITIONING_MODES = [ self::POSITIONING_MODE_COORDINATE, self::POSITIONING_MODE_STATIC_ADDRESS, ]; - const ANIMATIONS = [ + public const ANIMATIONS = [ Animation::BOUNCE, Animation::DROP, ]; - protected ContaoFramework $framework; - - protected Utils $utils; - - public function __construct(ContaoFramework $framework, Utils $utils) - { - $this->framework = $framework; - $this->utils = $utils; + public function __construct( + protected ContaoFramework $framework, + protected Utils $utils, + ) { parent::__construct(); } diff --git a/src/EventListener/Integrations/UtilsBundleEntityFinderFindEventListener.php b/src/EventListener/Integrations/UtilsBundleEntityFinderFindEventListener.php index eb0f4e4..f3d907a 100644 --- a/src/EventListener/Integrations/UtilsBundleEntityFinderFindEventListener.php +++ b/src/EventListener/Integrations/UtilsBundleEntityFinderFindEventListener.php @@ -16,7 +16,8 @@ class UtilsBundleEntityFinderFindEventListener { public function __construct( private readonly EntityFinderHelper $helper, - ) {} + ) { + } public function __invoke(EntityFinderFindEvent $event): void { @@ -42,15 +43,18 @@ private function overlay(EntityFinderFindEvent $event): void new Element( id: $overlay->id, table: OverlayModel::getTable(), - description: 'Google Maps Overlay: ' . $overlay->title . ' (ID: ' . $overlay->id . ')', + description: 'Google Maps Overlay: '.$overlay->title.' (ID: '.$overlay->id.')', parents: (function () use ($overlay): \Generator { - yield ['table' => GoogleMapModel::getTable(), 'id' => $overlay->pid]; + yield [ + 'table' => GoogleMapModel::getTable(), + 'id' => $overlay->pid, + ]; })() ) ); } - private function googleMaps(EntityFinderFindEvent $event) + private function googleMaps(EntityFinderFindEvent $event): void { $model = GoogleMapModel::findById($event->id); if (!$model) { @@ -61,48 +65,75 @@ private function googleMaps(EntityFinderFindEvent $event) new Element( id: $model->id, table: GoogleMapModel::getTable(), - description: 'Google Maps: ' . $model->title . ' (ID: ' . $model->id . ')', + description: 'Google Maps: '.$model->title.' (ID: '.$model->id.')', parents: (function () use ($model): \Generator { - - $contentElements = ContentModel::findBy(['googlemaps_map=?'], [$map->id]) ?? []; - + $contentElements = ContentModel::findBy(['googlemaps_map=?'], [$model->id]) ?? []; foreach ($contentElements as $contentElement) { - yield ['table' => ContentModel::getTable(), 'id' => $contentElement->id]; + yield [ + 'table' => ContentModel::getTable(), + 'id' => $contentElement->id, + ]; } - $frontendModules = ModuleModel::findBy(['googlemaps_map=?'], [$map->id]) ?? []; + $frontendModules = ModuleModel::findBy(['googlemaps_map=?'], [$model->id]) ?? []; foreach ($frontendModules as $frontendModule) { - yield ['table' => ModuleModel::getTable(), 'id' => $frontendModule->id]; + yield [ + 'table' => ModuleModel::getTable(), + 'id' => $frontendModule->id, + ]; } foreach ($this->helper->findModulesByInserttag('html', 'html', 'google_map', $model->id) as $module) { - yield ['table' => 'tl_module', 'id' => $module->id]; + yield [ + 'table' => 'tl_module', + 'id' => $module->id, + ]; } foreach ($this->helper->findModulesByInserttag('html', 'html', 'google_map_html', $model->id) as $module) { - yield ['table' => 'tl_module', 'id' => $module->id]; + yield [ + 'table' => 'tl_module', + 'id' => $module->id, + ]; } foreach ($this->helper->findModulesByInserttag('html', 'html', 'google_map_css', $model->id) as $module) { - yield ['table' => 'tl_module', 'id' => $module->id]; + yield [ + 'table' => 'tl_module', + 'id' => $module->id, + ]; } foreach ($this->helper->findModulesByInserttag('html', 'html', 'google_map_js', $model->id) as $module) { - yield ['table' => 'tl_module', 'id' => $module->id]; + yield [ + 'table' => 'tl_module', + 'id' => $module->id, + ]; } foreach ($this->helper->findContentElementByInserttag('html', 'html', 'google_map', $model->id) as $module) { - yield ['table' => 'tl_content', 'id' => $module->id]; + yield [ + 'table' => 'tl_content', + 'id' => $module->id, + ]; } foreach ($this->helper->findContentElementByInserttag('html', 'html', 'google_map_html', $model->id) as $module) { - yield ['table' => 'tl_content', 'id' => $module->id]; + yield [ + 'table' => 'tl_content', + 'id' => $module->id, + ]; } foreach ($this->helper->findContentElementByInserttag('html', 'html', 'google_map_css', $model->id) as $module) { - yield ['table' => 'tl_content', 'id' => $module->id]; + yield [ + 'table' => 'tl_content', + 'id' => $module->id, + ]; } foreach ($this->helper->findContentElementByInserttag('html', 'html', 'google_map_js', $model->id) as $module) { - yield ['table' => 'tl_content', 'id' => $module->id]; + yield [ + 'table' => 'tl_content', + 'id' => $module->id, + ]; } - })() ) ); } -} \ No newline at end of file +} diff --git a/src/EventListener/MapRendererListener.php b/src/EventListener/MapRendererListener.php index 0575e10..cb4bc09 100644 --- a/src/EventListener/MapRendererListener.php +++ b/src/EventListener/MapRendererListener.php @@ -21,20 +21,12 @@ class MapRendererListener { - protected GoogleMapModel $model; - - protected MapManager $manager; - - protected MapHelper $mapHelper; - - protected ContaoFramework $contaoFramework; - - public function __construct(GoogleMapModel $model, MapManager $manager, MapHelper $mapHelper, ContaoFramework $contaoFramework) - { - $this->model = $model; - $this->manager = $manager; - $this->mapHelper = $mapHelper; - $this->contaoFramework = $contaoFramework; + public function __construct( + protected GoogleMapModel $model, + protected MapManager $manager, + protected MapHelper $mapHelper, + protected ContaoFramework $contaoFramework, + ) { } public function renderStylesheet(MapEvent $event, string $eventName, EventDispatcherInterface $dispatcher): void diff --git a/src/EventListener/OveleonContaoCookiebarListener.php b/src/EventListener/OveleonContaoCookiebarListener.php index b49aabf..f4c841f 100644 --- a/src/EventListener/OveleonContaoCookiebarListener.php +++ b/src/EventListener/OveleonContaoCookiebarListener.php @@ -30,8 +30,7 @@ public function __construct( private readonly Utils $utils, private readonly Environment $twig, private readonly RequestStack $requestStack, - ) - { + ) { } #[AsHook('loadDataContainer')] @@ -44,15 +43,15 @@ public function onLoadDataContainer(string $table): void $dca = &$GLOBALS['TL_DCA']['tl_cookie']; $dca['fields']['type']['options'][] = static::TYPE; $dca['palettes'][self::TYPE] = $dca['palettes']['default']; -// PaletteManipulator::create() -// ->addField('blockTemplate', 'description_legend', PaletteManipulator::POSITION_APPEND) -// ->applyToPalette(self::TYPE, 'tl_cookie'); + // PaletteManipulator::create() + // ->addField('blockTemplate', 'description_legend', PaletteManipulator::POSITION_APPEND) + // ->applyToPalette(self::TYPE, 'tl_cookie'); } #[AsCallback(table: 'tl_cookie', target: 'fields.token.load')] public function requireField(mixed $varValue, DataContainer $dc): mixed { - if ((string)$dc->activeRecord->type === static::TYPE) { + if ((string) $dc->activeRecord->type === static::TYPE) { $GLOBALS['TL_DCA']['tl_cookie']['fields'][$dc->field]['eval']['mandatory'] = false; } @@ -80,6 +79,7 @@ public function onBeforeRenderApiEvent(BeforeRenderApiEvent $event): void if (!$apiSubscriber) { $event->setCode($this->maskScript($event->getCode(), $config['id'])); + return; } @@ -165,15 +165,13 @@ private function findConfig(): ?array return null; } - return array_find($cookies, function (array $cookie) { - return $cookie['type'] === static::TYPE; - }); + return array_find($cookies, fn (array $cookie) => $cookie['type'] === static::TYPE); } private function maskScript(string $script, int $configId, ?string $ident = null): string { if (!$ident) { - $ident = 'gmap_load_' . ByteString::fromRandom(4, '0123456789')->toString(); + $ident = 'gmap_load_'.ByteString::fromRandom(4, '0123456789')->toString(); } return <<< SCRIPT @@ -204,7 +202,7 @@ private function maskExternalResource(string $resource, int $configId, string $n private function addScriptToGlobals(string $script): void { $nonce = ByteString::fromRandom(4, '0123456789')->toString(); - $GLOBALS['TL_BODY']['huhGoogleMaps_' . $nonce] = $script; + $GLOBALS['TL_BODY']['huhGoogleMaps_'.$nonce] = $script; } private function parseHtml(string $content, Map $map, Request $request, CookieModel $configModel): string|array|bool|null @@ -218,8 +216,8 @@ private function parseHtml(string $content, Map $map, Request $request, CookieMo // support legacy path for bc $legacyTemplateName = '@Contao/oveleon_cookiebar/blocker/default.html.twig'; if ( - $this->twig->getLoader()->exists($legacyTemplateName) && - !str_contains( + $this->twig->getLoader()->exists($legacyTemplateName) + && !str_contains( $this->twig->getLoader()->getSourceContext($legacyTemplateName)->getPath(), 'heimrichhannot/contao-google-maps-bundle' ) @@ -243,10 +241,9 @@ private function parseHtml(string $content, Map $map, Request $request, CookieMo ]); return preg_replace( - '/(
]*>)/', - '$1' . $blocker, + '/(
]*>)/', + '$1'.$blocker, $content ); } - -} \ No newline at end of file +} diff --git a/src/EventListener/ReplaceDynamicScriptTagsListener.php b/src/EventListener/ReplaceDynamicScriptTagsListener.php index 5731bdf..fd82148 100644 --- a/src/EventListener/ReplaceDynamicScriptTagsListener.php +++ b/src/EventListener/ReplaceDynamicScriptTagsListener.php @@ -10,12 +10,10 @@ namespace HeimrichHannot\GoogleMapsBundle\EventListener; -use Contao\CoreBundle\ServiceAnnotation\Hook; +use Contao\CoreBundle\DependencyInjection\Attribute\AsHook; use HeimrichHannot\GoogleMapsBundle\Manager\MapManager; -/** - * @Hook("replaceDynamicScriptTags") - */ +#[AsHook('replaceDynamicScriptTags')] class ReplaceDynamicScriptTagsListener { /** diff --git a/src/HeimrichHannotGoogleMapsBundle.php b/src/HeimrichHannotGoogleMapsBundle.php index 31b8b0d..21d47d0 100644 --- a/src/HeimrichHannotGoogleMapsBundle.php +++ b/src/HeimrichHannotGoogleMapsBundle.php @@ -24,6 +24,4 @@ public function getPath(): string { return \dirname(__DIR__); } - - } diff --git a/src/Manager/MapManager.php b/src/Manager/MapManager.php index d6ba13b..182f0f6 100644 --- a/src/Manager/MapManager.php +++ b/src/Manager/MapManager.php @@ -51,19 +51,11 @@ class MapManager { - const CACHE_KEY_PREFIX = 'googleMaps_map'; + public const CACHE_KEY_PREFIX = 'googleMaps_map'; - const CACHE_TIME = 86400; + public const CACHE_TIME = 86400; - const GOOGLE_MAPS_STATIC_URL = 'https://maps.googleapis.com/maps/api/staticmap'; - - protected ContaoFramework $framework; - - protected OverlayManager $overlayManager; - - protected ModelUtil $modelUtil; - - protected LocationUtil $locationUtil; + public const GOOGLE_MAPS_STATIC_URL = 'https://maps.googleapis.com/maps/api/staticmap'; /** * @var string @@ -77,27 +69,17 @@ class MapManager */ protected $maps = []; - private FileUtil $fileUtil; - - private MapCollection $mapCollection; - - private EventDispatcherInterface $eventDispatcher; - - private CacheInterface $cache; - public function __construct( private readonly Utils $utils, - - ContaoFramework $framework, OverlayManager $overlayManager, ModelUtil $modelUtil, LocationUtil $locationUtil, FileUtil $fileUtil, MapCollection $mapCollection, EventDispatcherInterface $eventDispatcher, CacheInterface $cache) - { - $this->framework = $framework; - $this->overlayManager = $overlayManager; - $this->modelUtil = $modelUtil; - $this->locationUtil = $locationUtil; - $this->fileUtil = $fileUtil; - $this->mapCollection = $mapCollection; - $this->eventDispatcher = $eventDispatcher; - $this->cache = $cache; + protected ContaoFramework $framework, + protected OverlayManager $overlayManager, + protected ModelUtil $modelUtil, + protected LocationUtil $locationUtil, + private readonly FileUtil $fileUtil, + private readonly MapCollection $mapCollection, + private readonly EventDispatcherInterface $eventDispatcher, + private readonly CacheInterface $cache, + ) { } public function prepareMap(int $mapId, array $config = [], ?Collection $overlays = null): ?array @@ -250,7 +232,7 @@ public function renderApi(): string $apiHelper->getEventDispatcher()->addListener(ApiEvents::JAVASCRIPT, [$listener, 'onApiRender']); $output = $apiHelper->render($this->mapCollection->getMaps()); - + // Add loading=async parameter to Google Maps API URL for better performance $output = preg_replace( '/(https:\/\/maps\.googleapis\.com\/maps\/api\/js\?[^"\']*)/i', diff --git a/src/Manager/OverlayManager.php b/src/Manager/OverlayManager.php index a848f13..506b3e0 100644 --- a/src/Manager/OverlayManager.php +++ b/src/Manager/OverlayManager.php @@ -35,15 +35,9 @@ class OverlayManager { - const CACHE_KEY_PREFIX = 'googleMaps_overlay'; + public const CACHE_KEY_PREFIX = 'googleMaps_overlay'; - const CACHE_TIME = 86400; - - protected ContaoFramework $framework; - - protected ModelUtil $modelUtil; - - protected LocationUtil $locationUtil; + public const CACHE_TIME = 86400; /** * @var string @@ -55,25 +49,19 @@ class OverlayManager */ protected static $markerVariableMapping = []; - private FileUtil $fileUtil; - - private InsertTagParser $insertTagParser; - - private CacheInterface $cache; - - public function __construct(ContaoFramework $framework, ModelUtil $modelUtil, LocationUtil $locationUtil, FileUtil $fileUtil, InsertTagParser $insertTagParser, CacheInterface $cache) - { - $this->framework = $framework; - $this->modelUtil = $modelUtil; - $this->locationUtil = $locationUtil; - $this->fileUtil = $fileUtil; - $this->insertTagParser = $insertTagParser; - $this->cache = $cache; + public function __construct( + protected ContaoFramework $framework, + protected ModelUtil $modelUtil, + protected LocationUtil $locationUtil, + private readonly FileUtil $fileUtil, + private readonly InsertTagParser $insertTagParser, + private readonly CacheInterface $cache, + ) { } public function addOverlayToMap(Map $map, OverlayModel $overlayConfig, string $apiKey): void { - $this->apiKey = $apiKey; + self::$apiKey = $apiKey; switch ($overlayConfig->type) { case OverlayListener::TYPE_MARKER: @@ -152,7 +140,7 @@ public function setPositioning($overlay, OverlayModel $overlayConfig): void function (ItemInterface $item) use ($overlayConfig) { $item->expiresAfter(static::CACHE_TIME); - $coordinates = $this->locationUtil->computeCoordinatesByString($overlayConfig->positioningAddress, $this->apiKey); + $coordinates = $this->locationUtil->computeCoordinatesByString($overlayConfig->positioningAddress, self::$apiKey); if (false === $coordinates) { trigger_error('Could not compute coordinates from address. Maybe your Google API key is invalid or geocoding API is not enabled.', E_USER_WARNING); @@ -258,7 +246,9 @@ protected function prepareMarker(OverlayModel $overlayConfig, Map $map) // events if ($overlayConfig->clickEvent) { - $marker->addOptions(['clickable' => true]); + $marker->addOptions([ + 'clickable' => true, + ]); switch ($overlayConfig->clickEvent) { case OverlayListener::CLICK_EVENT_LINK: diff --git a/src/MapBuilder/MapBuilder.php b/src/MapBuilder/MapBuilder.php index 5007e81..c613fe1 100644 --- a/src/MapBuilder/MapBuilder.php +++ b/src/MapBuilder/MapBuilder.php @@ -8,7 +8,6 @@ use HeimrichHannot\GoogleMapsBundle\Manager\MapManager; use HeimrichHannot\GoogleMapsBundle\Manager\OverlayManager; use HeimrichHannot\GoogleMapsBundle\Model\OverlayModel; -use HeimrichHannot\GoogleMapsBundle\MapBuilder\MarkerHelper; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; @@ -22,27 +21,31 @@ class MapBuilder implements \Stringable private array $mapTemplateData; public function __construct( - private readonly MapManager $mapManager, + private readonly MapManager $mapManager, private readonly EventDispatcherInterface $eventDispatcher, private readonly OverlayManager $overlayManager, private readonly RequestStack $requestStack, - ) {} + ) { + } public function setMapId(int $id): self { $this->mapId = $id; + return $this; } public function setConfig(array $config): self { $this->mapTemplateData = $config; + return $this; } public function addConfig(string $key, $value): self { $this->mapTemplateData[$key] = $value; + return $this; } @@ -53,13 +56,13 @@ public function setMapIfIfExist(mixed $mapId): self } if (is_scalar($mapId)) { - return $this->setMapId((int)$mapId); + return $this->setMapId((int) $mapId); } if (is_array($mapId)) { foreach ($mapId as $id) { if (is_scalar($id)) { - $this->setMapIfIfExist((int)$id); + $this->setMapIfIfExist((int) $id); if (isset($this->mapId)) { return $this; } @@ -76,6 +79,7 @@ public function addOverlays(array|Collection $overlays): self throw new \RuntimeException('Map already build.'); } $this->overlays = $overlays; + return $this; } @@ -109,6 +113,7 @@ public function build(array $config = []): self $this->mapTemplateData = $templateData; $this->prepared = true; + return $this; } @@ -129,7 +134,6 @@ public function getMarker(int $id): ?MarkerHelper ); } - public function __toString(): string { return $this->toString(); @@ -153,6 +157,7 @@ public function withConfig(array $config = []): self { $new = clone $this; $new->mapTemplateData = array_merge($new->mapTemplateData ?? [], $config); + return $new; } @@ -189,7 +194,6 @@ private function buildOverlays(): ?Collection $overlays = []; foreach ($this->overlays as $overlayData) { - if ($overlayData instanceof OverlayModel) { $model = $overlayData; $overlayData = $model->row(); diff --git a/src/MapBuilder/MapBuilderFactory.php b/src/MapBuilder/MapBuilderFactory.php index 08371b3..2787fd5 100644 --- a/src/MapBuilder/MapBuilderFactory.php +++ b/src/MapBuilder/MapBuilderFactory.php @@ -4,7 +4,6 @@ use HeimrichHannot\GoogleMapsBundle\Manager\MapManager; use HeimrichHannot\GoogleMapsBundle\Manager\OverlayManager; -use HeimrichHannot\GoogleMapsBundle\MapBuilder\MapBuilder; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; @@ -15,7 +14,8 @@ public function __construct( private readonly EventDispatcherInterface $eventDispatcher, private readonly OverlayManager $overlayManager, private readonly RequestStack $requestStack, - ) {} + ) { + } public function build(): MapBuilder { @@ -26,4 +26,4 @@ public function build(): MapBuilder $this->requestStack, ); } -} \ No newline at end of file +} diff --git a/src/MapBuilder/MarkerHelper.php b/src/MapBuilder/MarkerHelper.php index 6886f21..46ac6df 100644 --- a/src/MapBuilder/MarkerHelper.php +++ b/src/MapBuilder/MarkerHelper.php @@ -8,8 +8,9 @@ class MarkerHelper { public function __construct( public readonly string $variable, - public readonly Request $request - ) {} + public readonly Request $request, + ) { + } public function trigger(): string { @@ -18,4 +19,4 @@ public function trigger(): string $this->variable ); } -} \ No newline at end of file +} diff --git a/src/Security/Voter/GoogleMapAccessVoter.php b/src/Security/Voter/GoogleMapAccessVoter.php index c72e2c9..29f47ae 100644 --- a/src/Security/Voter/GoogleMapAccessVoter.php +++ b/src/Security/Voter/GoogleMapAccessVoter.php @@ -24,8 +24,9 @@ */ class GoogleMapAccessVoter extends AbstractDataContainerVoter { - public function __construct(private readonly AccessDecisionManagerInterface $accessDecisionManager) - { + public function __construct( + private readonly AccessDecisionManagerInterface $accessDecisionManager, + ) { } protected function getTable(): string diff --git a/src/Service/ElevationService.php b/src/Service/ElevationService.php index a196f9b..2ee3c54 100644 --- a/src/Service/ElevationService.php +++ b/src/Service/ElevationService.php @@ -11,31 +11,29 @@ namespace HeimrichHannot\GoogleMapsBundle\Service; use Contao\Config; -use Http\Client\HttpClient; use Http\Message\MessageFactory\GuzzleMessageFactory; use Ivory\GoogleMap\Base\Coordinate; use Ivory\GoogleMap\Service\Base\Location\CoordinateLocation; +use Ivory\GoogleMap\Service\Elevation\Request\ElevationRequestInterface; use Ivory\GoogleMap\Service\Elevation\Request\PathElevationRequest; use Ivory\GoogleMap\Service\Elevation\Request\PositionalElevationRequest; use Ivory\GoogleMap\Service\Elevation\Response\ElevationResult; +use Psr\Http\Client\ClientInterface; class ElevationService { - const REQUEST_TYPE_PATH = 'path'; + public const REQUEST_TYPE_PATH = 'path'; - const REQUEST_TYPE_POSTITIONAL = 'positional'; + public const REQUEST_TYPE_POSTITIONAL = 'positional'; - const MAX_SAMPLES = 300; + public const MAX_SAMPLES = 300; /** * @var \Ivory\GoogleMap\Service\Elevation\ElevationService */ protected $service; - /** - * ElevationService constructor. - */ - public function __construct(HttpClient $httpClient) + public function __construct(ClientInterface $httpClient) { $this->service = new \Ivory\GoogleMap\Service\Elevation\ElevationService($httpClient, new GuzzleMessageFactory()); @@ -67,7 +65,7 @@ public function prepareCoordinates(array $coordinates): array continue; } - if (!\is_array($coordinate) && !\is_array($coordinate = explode(',', $coordinate))) { + if (!\is_array($coordinate) && !\is_array($coordinate = explode(',', (string) $coordinate))) { continue; } @@ -78,21 +76,15 @@ public function prepareCoordinates(array $coordinates): array } /** - * @return PathElevationRequest|PositionalElevationRequest + * @return PathElevationRequest|PositionalElevationRequest|ElevationRequestInterface */ - public function getRequest(array $locations, $type = self::REQUEST_TYPE_POSTITIONAL) + public function getRequest(array $locations, $type = self::REQUEST_TYPE_POSTITIONAL): ElevationRequestInterface { - switch ($type) { - case self::REQUEST_TYPE_POSTITIONAL: - return new PositionalElevationRequest($locations); - - break; - - case self::REQUEST_TYPE_PATH: - return new PathElevationRequest([$locations[0], end($locations)]); - - break; - } + return match ($type) { + self::REQUEST_TYPE_POSTITIONAL => new PositionalElevationRequest($locations), + self::REQUEST_TYPE_PATH => new PathElevationRequest([$locations[0], end($locations)]), + default => throw new \RuntimeException('Unsupported request type'), + }; } public function setService(\Ivory\GoogleMap\Service\Elevation\ElevationService $service): void diff --git a/src/Twig/GoogleMapsExtension.php b/src/Twig/GoogleMapsExtension.php index 6a36eca..d72fede 100644 --- a/src/Twig/GoogleMapsExtension.php +++ b/src/Twig/GoogleMapsExtension.php @@ -32,7 +32,9 @@ public function getFunctions(): array new TwigFunction( 'google_map', [GoogleMapsRuntime::class, 'create'], - ['is_safe' => ['html']] + [ + 'is_safe' => ['html'], + ] ), ]; diff --git a/src/Twig/GoogleMapsRuntime.php b/src/Twig/GoogleMapsRuntime.php index e85fd4d..277a5fc 100644 --- a/src/Twig/GoogleMapsRuntime.php +++ b/src/Twig/GoogleMapsRuntime.php @@ -12,11 +12,12 @@ class GoogleMapsRuntime implements RuntimeExtensionInterface public function __construct( private readonly MapManager $mapManager, private readonly MapBuilderFactory $mapBuilderFactory, - ) {} + ) { + } public function render(int $mapId, array $context = []): string { - return $this->mapManager->render($mapId,); + return $this->mapManager->render($mapId); } public function renderHtml(int $mapId): string @@ -40,5 +41,4 @@ public function create(?int $id = null): MapBuilder ->build() ->setMapIfIfExist($id); } - -} \ No newline at end of file +} diff --git a/src/Util/ArrayUtil.php b/src/Util/ArrayUtil.php index 74c96a5..de76b42 100644 --- a/src/Util/ArrayUtil.php +++ b/src/Util/ArrayUtil.php @@ -15,8 +15,8 @@ class ArrayUtil public static function removePrefix(string $prefix, array $array): array { $array = array_combine( - array_map(static fn ($key) => str_starts_with($key, $prefix) ? - substr($key, \strlen($prefix)) : $key, array_keys($array)), + array_map(static fn ($key) => str_starts_with((string) $key, $prefix) ? + substr((string) $key, \strlen($prefix)) : $key, array_keys($array)), $array, ); diff --git a/src/Util/DcaUtil.php b/src/Util/DcaUtil.php index a71bf5a..7ca814c 100644 --- a/src/Util/DcaUtil.php +++ b/src/Util/DcaUtil.php @@ -21,17 +21,11 @@ class DcaUtil { - protected ContaoFramework $framework; - - protected TranslatorInterface $translator; - - protected Utils $utils; - - public function __construct(ContaoFramework $framework, TranslatorInterface $translator, Utils $utils) - { - $this->framework = $framework; - $this->translator = $translator; - $this->utils = $utils; + public function __construct( + protected ContaoFramework $framework, + protected TranslatorInterface $translator, + protected Utils $utils, + ) { } /** @@ -78,12 +72,16 @@ public function addOverridableFields(array $fields, string $sourceTable, string foreach ($fields as $field) { // add override boolean field - $overrideFieldname = 'override'.ucfirst($field); + $overrideFieldname = 'override'.ucfirst((string) $field); $destinationDca['fields'][$overrideFieldname] = [ 'label' => &$GLOBALS['TL_LANG'][$destinationTable][$overrideFieldname], 'inputType' => 'checkbox', - 'eval' => ['tl_class' => 'w50', 'submitOnChange' => true, 'isOverrideSelector' => true], + 'eval' => [ + 'tl_class' => 'w50', + 'submitOnChange' => true, + 'isOverrideSelector' => true, + ], 'sql' => "char(1) NOT NULL default ''", ]; diff --git a/src/Util/LocationUtil.php b/src/Util/LocationUtil.php index 88ebc9a..a023d02 100644 --- a/src/Util/LocationUtil.php +++ b/src/Util/LocationUtil.php @@ -20,19 +20,13 @@ class LocationUtil { - const GOOGLE_MAPS_GEOCODE_URL = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false'; + public const GOOGLE_MAPS_GEOCODE_URL = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false'; - protected ContaoFramework $framework; - - protected Utils $utils; - - protected LoggerInterface $logger; - - public function __construct(ContaoFramework $framework, Utils $utils, LoggerInterface $logger) - { - $this->framework = $framework; - $this->utils = $utils; - $this->logger = $logger; + public function __construct( + protected ContaoFramework $framework, + protected Utils $utils, + protected LoggerInterface $logger, + ) { } /** @@ -75,7 +69,9 @@ public function computeCoordinatesByString(string $address, string $apiKey = '') } catch (\Exception $e) { $this->logger->error( $e->getMessage(), - ['contao' => new ContaoContext(__METHOD__, ContaoContext::ERROR)], + [ + 'contao' => new ContaoContext(__METHOD__, ContaoContext::ERROR), + ], ); return false;