Skip to content

Commit

Permalink
Consider getImageSizes within `LegacyFrameworkCallToServiceCallRect…
Browse files Browse the repository at this point in the history
…or` (#9)
  • Loading branch information
zoglo authored May 13, 2024
1 parent 426478a commit bdf77d0
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config/sets/contao/contao-49.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
use Contao\Rector\Rector\ConstantToServiceParameterRector;
use Contao\Rector\Rector\ControllerMethodToVersionsClassRector;
use Contao\Rector\Rector\LegacyFrameworkCallToInstanceCallRector;
use Contao\Rector\Rector\LegacyFrameworkCallToServiceCallRector;
use Contao\Rector\Rector\LegacyFrameworkCallToStaticCallRector;
use Contao\Rector\Rector\LoginConstantsToSymfonySecurityRector;
use Contao\Rector\Rector\ModeConstantToScopeMatcherRector;
use Contao\Rector\Rector\SystemLogToMonologRector;
use Contao\Rector\ValueObject\ConstantToClassConstant;
use Contao\Rector\ValueObject\ConstantToServiceParameter;
use Contao\Rector\ValueObject\LegacyFrameworkCallToInstanceCall;
use Contao\Rector\ValueObject\LegacyFrameworkCallToServiceCall;
use Contao\Rector\ValueObject\LegacyFrameworkCallToStaticCall;
use Contao\StringUtil;
use Contao\System;
use Contao\Widget;
use Rector\Config\RectorConfig;
use Rector\Removing\Rector\Class_\RemoveInterfacesRector;
Expand Down Expand Up @@ -107,6 +110,11 @@
new ConstantToServiceParameter('TL_ROOT', 'kernel.project_dir'),
]);

// Contao 4.1
$rectorConfig->ruleWithConfiguration(LegacyFrameworkCallToServiceCallRector::class, [
new LegacyFrameworkCallToServiceCall(System::class, 'getImageSizes', 'contao.image.sizes', 'getAllOptions'),
]);

// Contao 4.2
$rectorConfig->ruleWithConfiguration(ConstantToClassConstantRector::class, [
new ConstantToClassConstant('TL_ERROR', ContaoContext::class, 'ERROR'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Contao\Controller;
use Contao\Rector\Rector\LegacyFrameworkCallToServiceCallRector;
use Contao\Rector\ValueObject\LegacyFrameworkCallToServiceCall;
use Contao\System;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(LegacyFrameworkCallToServiceCallRector::class, [
new LegacyFrameworkCallToServiceCall(Controller::class, 'parseSimpleTokens', 'contao.string.simple_token_parser', 'parse')
new LegacyFrameworkCallToServiceCall(Controller::class, 'parseSimpleTokens', 'contao.string.simple_token_parser', 'parse'),
new LegacyFrameworkCallToServiceCall(System::class, 'getImageSizes', 'contao.image.sizes', 'getAllOptions')
]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class Foo
{
public function bar()
{
$sizes = \Contao\System::getImageSizes();
}
}
?>
-----
<?php

class Foo
{
public function bar()
{
$sizes = \Contao\System::getContainer()->get('contao.image.sizes')->getAllOptions();
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

class Foo
{
public function bar()
{
$GLOBALS['TL_DCA']['tl_foo']['fields']['size'] = [
'label' => &$GLOBALS['TL_LANG']['tl_content']['size'],
'exclude' => true,
'inputType' => 'imageSize',
'options' => \Contao\System::getImageSizes(),
'reference' => &$GLOBALS['TL_LANG']['MSC'],
'eval' => array('rgxp'=>'natural', 'includeBlankOption'=>true, 'nospace'=>true, 'helpwizard'=>true, 'tl_class'=>'w50'),
'sql' => "varchar(64) NOT NULL default ''"
];
}
}
?>
-----
<?php

class Foo
{
public function bar()
{
$GLOBALS['TL_DCA']['tl_foo']['fields']['size'] = [
'label' => &$GLOBALS['TL_LANG']['tl_content']['size'],
'exclude' => true,
'inputType' => 'imageSize',
'options' => \Contao\System::getContainer()->get('contao.image.sizes')->getAllOptions(),
'reference' => &$GLOBALS['TL_LANG']['MSC'],
'eval' => array('rgxp'=>'natural', 'includeBlankOption'=>true, 'nospace'=>true, 'helpwizard'=>true, 'tl_class'=>'w50'),
'sql' => "varchar(64) NOT NULL default ''"
];
}
}
?>

0 comments on commit bdf77d0

Please sign in to comment.