Skip to content

Commit

Permalink
Backport for SonataCoreBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk authored and greg0ire committed May 9, 2020
1 parent 5102f8c commit 01c461f
Show file tree
Hide file tree
Showing 18 changed files with 496 additions and 123 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ branches:
only:
- master
- 1.x
- 0.x

language: php

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"twig/twig": "^2.0 || ^3.0"
},
"conflict": {
"sonata-project/core-bundle": ">=3.13"
"sonata-project/core-bundle": "<3.19"
},
"require-dev": {
"jms/serializer-bundle": "^3.3",
Expand All @@ -48,7 +48,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
"dev-master": "0.x-dev"
}
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ parameters:
# - tests

excludes_analyse:
- src/Test/AbstractWidgetTestCase.php
- tests/bootstrap.php

autoload_files:
- vendor/autoload.php

ignoreErrors:
- '#Class Symfony\\Component\\Translation\\TranslatorInterface not found.#'
33 changes: 0 additions & 33 deletions src/Bridge/Symfony/Bundle/SonataTwigBundle.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function load(array $configs, ContainerBuilder $container): void
/**
* Registers flash message types defined in configuration to flash manager.
*/
public function registerFlashTypes(ContainerBuilder $container, array $config): void
private function registerFlashTypes(ContainerBuilder $container, array $config): void
{
$mergedConfig = array_merge_recursive($config['flashmessage'], [
'success' => ['types' => [
Expand Down
8 changes: 5 additions & 3 deletions src/Extension/DeprecatedTemplateExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

/**
* @author Marko Kunic <[email protected]>
*
* @final since sonata-project/twig-extensions 0.x
*/
final class DeprecatedTemplateExtension extends AbstractExtension
class DeprecatedTemplateExtension extends AbstractExtension
{
/**
* {@inheritdoc}
* @return array
*/
public function getTokenParsers(): array
public function getTokenParsers()
{
return [
new DeprecatedTemplateTokenParser(),
Expand Down
14 changes: 11 additions & 3 deletions src/Extension/FlashMessageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,26 @@
*
* @author Vincent Composieux <[email protected]>
* @author Titouan Galopin <[email protected]>
*
* @final since sonata-project/twig-extensions 0.x
*/
final class FlashMessageExtension extends AbstractExtension
class FlashMessageExtension extends AbstractExtension
{
public function getFunctions(): array
/**
* @return TwigFunction[]
*/
public function getFunctions()
{
return [
new TwigFunction('sonata_flashmessages_get', [FlashMessageRuntime::class, 'getFlashMessages']),
new TwigFunction('sonata_flashmessages_types', [FlashMessageRuntime::class, 'getFlashMessagesTypes']),
];
}

public function getName(): string
/**
* @return string
*/
public function getName()
{
return 'sonata_twig_flashmessage';
}
Expand Down
17 changes: 12 additions & 5 deletions src/Extension/FlashMessageRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
*
* @author Vincent Composieux <[email protected]>
* @author Titouan Galopin <[email protected]>
*
* @final since sonata-project/twig-extensions 0.x
*/
final class FlashMessageRuntime
class FlashMessageRuntime
{
/**
* @var FlashManager
Expand All @@ -36,17 +38,22 @@ public function __construct(FlashManager $flashManager)
/**
* Returns flash messages handled by Sonata flash manager.
*
* @param string $type Type of flash message
* @param string $type Type of flash message
* @param string|null $deprecatedDomain Translation domain to use
*
* @return array
*/
public function getFlashMessages(string $type): array
public function getFlashMessages($type, $deprecatedDomain = null)
{
return $this->flashManager->get($type);
return $this->flashManager->get($type, $deprecatedDomain);
}

/**
* Returns flash messages types handled by Sonata flash manager.
*
* @return array
*/
public function getFlashMessagesTypes(): array
public function getFlashMessagesTypes()
{
return $this->flashManager->getHandledTypes();
}
Expand Down
74 changes: 58 additions & 16 deletions src/Extension/FormTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,69 @@
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;

final class FormTypeExtension extends AbstractExtension implements GlobalsInterface
{
if (class_exists('Twig_Extension_GlobalsInterface')) {
/**
* @var bool
* @final since sonata-project/twig-extensions 0.x
*/
private $wrapFieldsWithAddons;

public function __construct($formType)
class FormTypeExtension extends AbstractExtension implements GlobalsInterface
{
$this->wrapFieldsWithAddons = (true === $formType || 'standard' === $formType);
}
/**
* @var bool
*/
private $wrapFieldsWithAddons;

public function getGlobals(): array
{
return [
'wrap_fields_with_addons' => $this->wrapFieldsWithAddons,
];
}
public function __construct($formType)
{
$this->wrapFieldsWithAddons = (true === $formType || 'standard' === $formType);
}

/**
* @return array
*/
public function getGlobals()
{
return [
'wrap_fields_with_addons' => $this->wrapFieldsWithAddons,
];
}

public function getName(): string
/**
* @return string
*/
public function getName()
{
return 'sonata_twig_wrapping';
}
}
} else {
/**
* @final since sonata-project/twig-extensions 0.x
*/
class FormTypeExtension extends AbstractExtension implements GlobalsInterface
{
return 'sonata_twig_wrapping';
/**
* @var bool
*/
private $wrapFieldsWithAddons;

public function __construct($formType)
{
$this->wrapFieldsWithAddons = (true === $formType || 'standard' === $formType);
}

public function getGlobals(): array
{
return [
'wrap_fields_with_addons' => $this->wrapFieldsWithAddons,
];
}

/**
* @return string
*/
public function getName()
{
return 'sonata_twig_wrapping';
}
}
}
4 changes: 3 additions & 1 deletion src/Extension/StatusExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
/**
* @author Hugo Briand <[email protected]>
* @author Titouan Galopin <[email protected]>
*
* @final since sonata-project/twig-extensions 0.x
*/
final class StatusExtension extends AbstractExtension
class StatusExtension extends AbstractExtension
{
public function getFilters(): array
{
Expand Down
14 changes: 10 additions & 4 deletions src/Extension/StatusRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
/**
* @author Hugo Briand <[email protected]>
* @author Titouan Galopin <[email protected]>
*
* @final since sonata-project/twig-extensions 0.x
*/
final class StatusRuntime
class StatusRuntime
{
/**
* @var StatusClassRendererInterface[]
Expand All @@ -29,15 +31,19 @@ final class StatusRuntime
/**
* Adds a renderer to the status services list.
*/
public function addStatusService(StatusClassRendererInterface $renderer): void
public function addStatusService(StatusClassRendererInterface $renderer)
{
$this->statusServices[] = $renderer;
}

/**
* @param mixed $statusType
* @param object $object
* @param mixed|null $statusType
* @param string $default
*
* @return string
*/
public function statusClass(object $object, $statusType = null, string $default = ''): string
public function statusClass($object, $statusType = null, $default = '')
{
foreach ($this->statusServices as $statusService) {
\assert($statusService instanceof StatusClassRendererInterface);
Expand Down
Loading

0 comments on commit 01c461f

Please sign in to comment.