Skip to content

Commit

Permalink
Stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk authored and greg0ire committed Jun 4, 2020
1 parent c51c2b0 commit 71a84ea
Show file tree
Hide file tree
Showing 39 changed files with 777 additions and 472 deletions.
36 changes: 19 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,31 @@
"jms/metadata": "^2.1",
"jms/serializer": "^2.0 || ^3.0",
"sonata-project/doctrine-extensions": "^1.1",
"symfony/event-dispatcher": "^3.4 || ^4.3 || ^5.0",
"symfony/form": "^3.4.24 || ^4.3 || ^5.0",
"symfony/options-resolver": "^3.4 || ^4.3 || ^5.0",
"symfony/property-access": "^3.4 || ^4.3 || ^5.0",
"symfony/security-csrf": "^3.4 || ^4.3 || ^5.0",
"symfony/translation": "^3.4 || ^4.3 || ^5.0",
"symfony/validator": "^3.4 || ^4.3 || ^5.0",
"twig/twig": "^2.0 || ^3.0"
"symfony/event-dispatcher": "^4.3",
"symfony/form": "^4.3",
"symfony/options-resolver": "^4.3",
"symfony/property-access": "^4.3",
"symfony/security-csrf": "^4.3",
"symfony/translation": "^4.3",
"symfony/validator": "^4.3",
"twig/twig": "^2.12.1"
},
"conflict": {
"sonata-project/core-bundle": "<3.19"
"sonata-project/core-bundle": "<3.20"
},
"require-dev": {
"doctrine/persistence": "^1.1",
"matthiasnoback/symfony-config-test": "^4.0",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"symfony/config": "^3.4 || ^4.3 || ^5.0",
"symfony/dependency-injection": "^3.4 || ^4.3 || ^5.0",
"symfony/framework-bundle": "^3.4 || ^4.3 || ^5.0",
"symfony/http-foundation": "^3.4 || ^4.3 || ^5.0",
"symfony/http-kernel": "^3.4 || ^4.3 || ^5.0",
"matthiasnoback/symfony-config-test": "^4.2",
"matthiasnoback/symfony-dependency-injection-test": "^4.1",
"symfony/browser-kit": "^4.3",
"symfony/config": "^4.3",
"symfony/dependency-injection": "^4.3",
"symfony/framework-bundle": "^4.3",
"symfony/http-foundation": "^4.3",
"symfony/http-kernel": "^4.3",
"symfony/phpunit-bridge": "^5.0",
"symfony/twig-bridge": "^3.4 || ^4.3 || ^5.0"
"symfony/twig-bridge": "^4.3",
"symfony/twig-bundle": "^4.3"
},
"suggest": {
"doctrine/persistence": "If you want to use BaseDoctrineORMSerializationType"
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ parameters:

ignoreErrors:
- '#Class Sonata\\Form\\Validator\\LegacyExecutionContextInterface not found.#'
- '#Class Symfony\\Component\\Translation\\TranslatorInterface not found.#'
2 changes: 0 additions & 2 deletions src/Bridge/Symfony/Resources/config/form_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
<tag name="form.type" alias="sonata_type_date_picker"/>
<argument type="service" id="sonata.form.date.moment_format_converter"/>
<argument type="service" id="translator"/>
<argument type="service" id="request_stack"/>
</service>
<service id="sonata.form.type.datetime_picker" class="Sonata\Form\Type\DateTimePickerType">
<tag name="form.type" alias="sonata_type_datetime_picker"/>
<argument type="service" id="sonata.form.date.moment_format_converter"/>
<argument type="service" id="translator"/>
<argument type="service" id="request_stack"/>
</service>
<service id="sonata.form.type.date_range_picker" class="Sonata\Form\Type\DateRangePickerType">
<tag name="form.type" alias="sonata_type_date_range_picker"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<source>label_type_no</source>
<target>нет</target>
</trans-unit>
<trans-unit id="sonata_form_template_box_file_found_in">
<source>sonata_form_template_box_file_found_in</source>
<target>Этот файл можно найти в</target>
</trans-unit>
<trans-unit id="label_type_equals">
<source>label_type_equals</source>
<target>равен</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,13 @@
* file that was distributed with this source code.
*/

namespace Sonata\Form\Bridge\Symfony\Bundle;
namespace Sonata\Form\Bridge\Symfony;

use Sonata\Form\Bridge\Symfony\DependencyInjection\SonataFormExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;

final class SonataFormBundle extends Bundle
{
/**
* @return string
*/
public function getPath()
{
return __DIR__.'/..';
}

/**
* @return string
*/
Expand Down
1 change: 0 additions & 1 deletion src/Date/MomentFormatConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class MomentFormatConverter
public function convert($format)
{
$size = \strlen($format);

$output = '';
//process the format string letter by letter
for ($i = 0; $i < $size; ++$i) {
Expand Down
15 changes: 14 additions & 1 deletion src/EventListener/FixCheckboxDataListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@ class FixCheckboxDataListener implements EventSubscriberInterface
*/
public static function getSubscribedEvents()
{
return [FormEvents::PRE_SUBMIT => 'preSubmit'];
/*
* NEXT_MAJOR: change preBind to preSubmit
*/
return [FormEvents::PRE_SUBMIT => 'preBind'];
}

/**
* NEXT_MAJOR: remove this method.
*
* @deprecated since sonata-project/form-extensions 0.x, to be removed in 1.0. Use Use {@link preSubmit} instead.
*/
public function preBind(FormEvent $event)
{
$this->preSubmit($event);
}

public function preSubmit(FormEvent $event)
Expand Down
24 changes: 22 additions & 2 deletions src/EventListener/ResizeFormListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,31 @@ public static function getSubscribedEvents()
{
return [
FormEvents::PRE_SET_DATA => 'preSetData',
FormEvents::PRE_SUBMIT => 'preSubmit',
FormEvents::SUBMIT => 'onSubmit',
FormEvents::PRE_SUBMIT => 'preBind',
FormEvents::SUBMIT => 'onBind',
];
}

/**
* NEXT_MAJOR: remove this method.
*
* @deprecated since sonata-project/form-extensions 0.x, to be renamed in 1.0. Use {@link preSubmit} instead.
*/
public function preBind(FormEvent $event)
{
$this->preSubmit($event);
}

/**
* NEXT_MAJOR: remove this method.
*
* @deprecated since sonata-project/form-extensions 0.x, to be renamed in 1.0. Use {@link onSubmit} instead.
*/
public function onBind(FormEvent $event)
{
$this->onSubmit($event);
}

/**
* @throws UnexpectedTypeException
*/
Expand Down
12 changes: 11 additions & 1 deletion src/Serializer/BaseSerializerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ final public static function addFormat($format)
*/
public static function getSubscribingMethods()
{
// NEXT_MAJOR : remove this block
if (null === static::$formats) {
static::$formats = ['json', 'xml', 'yml'];
@trigger_error(sprintf(
'%s::$formats has been set by default to array("json", "xml", "yml"). Ability to set them to a
different value is deprecated since sonata-project/form-bundle 0.x and will be removed in version 1.0. Use "sonata_form.serializer.formats" configuration instead.',
__CLASS__
), E_USER_DEPRECATED);
}

$type = static::getType();
$methods = [];

Expand Down Expand Up @@ -88,7 +98,7 @@ public static function getSubscribingMethods()
*
* @return int|null
*/
public function serializeObjectToId(VisitorInterface $visitor, $data, $type, Context $context)
public function serializeObjectToId(VisitorInterface $visitor, $data, array $type, Context $context)
{
$className = $this->manager->getClass();

Expand Down
57 changes: 45 additions & 12 deletions src/Test/AbstractWidgetTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@

namespace Sonata\Form\Test;

use Sonata\Form\Fixtures\StubFilesystemLoader;
use Sonata\Form\Fixtures\StubTranslator;
use Symfony\Bridge\Twig\AppVariable;
use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Bridge\Twig\Form\TwigRenderer;
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
use Symfony\Component\Form\FormExtensionInterface;
use Symfony\Component\Form\FormRenderer;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Twig\Extension\InitRuntimeInterface;
use Twig\RuntimeLoader\FactoryRuntimeLoader;

/**
Expand All @@ -32,6 +36,11 @@
*/
abstract class AbstractWidgetTestCase extends TypeTestCase
{
/**
* @var FormExtensionInterface
*/
private $extension;

/**
* @var FormRenderer
*/
Expand All @@ -41,34 +50,44 @@ protected function setUp(): void
{
parent::setUp();

$this->extension = new FormExtension();
$environment = $this->getEnvironment();

$this->renderer = new FormRenderer(
$this->getRenderingEngine($environment),
$this->createMock(CsrfTokenManagerInterface::class)
);
$runtimeLoader = new FactoryRuntimeLoader([
FormRenderer::class => [$this, 'getRenderer'],
TwigRenderer::class => [$this, 'getRenderer'],
]);

$environment->addRuntimeLoader($runtimeLoader);

$environment->addRuntimeLoader(new FactoryRuntimeLoader([
FormRenderer::class => function () {
return $this->renderer;
},
]));
$environment->addExtension(new FormExtension());
if ($this->extension instanceof InitRuntimeInterface) {
$this->extension->initRuntime($environment);
}
}

final public function getRenderer(): FormRenderer
/**
* @return FormRenderer
*/
final public function getRenderer()
{
return $this->renderer;
}

protected function getEnvironment(): Environment
/**
* @return Environment
*/
protected function getEnvironment()
{
$loader = new FilesystemLoader($this->getTemplatePaths());
$loader = new StubFilesystemLoader($this->getTemplatePaths());

$environment = new Environment($loader, [
'strict_variables' => true,
]);
$environment->addExtension(new TranslationExtension(new StubTranslator()));
$environment->addExtension($this->extension);

return $environment;
}
Expand Down Expand Up @@ -97,8 +116,22 @@ protected function getTemplatePaths()
return $twigPaths;
}

protected function getRenderingEngine(Environment $environment)
/**
* NEXT_MAJOR: uncomment and use the $environment argument.
*
* @return TwigRendererEngine
*/
protected function getRenderingEngine(/* \Twig_Environment $environment = null */)
{
$environment = current(\func_get_args());
if (null === $environment && method_exists(AppVariable::class, 'getToken')) {
@trigger_error(
'Not passing a \Twig_Environment instance to '.__METHOD__.
' is deprecated since 0.x and will not be possible in 1.0',
E_USER_DEPRECATED
);
}

return new TwigRendererEngine(['form_div_layout.html.twig'], $environment);
}

Expand Down
Loading

0 comments on commit 71a84ea

Please sign in to comment.