deprecate using invalid names for buttons

This commit is contained in:
Christian Flothmann 2018-10-24 15:24:37 +02:00
parent 2cad97b0b5
commit 405aa548eb
5 changed files with 32 additions and 2 deletions

View File

@ -23,6 +23,10 @@ Config
Form
----
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
exception in 5.0.
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
will lead to an exception in 5.0.
* Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is
set to `single_text` is deprecated.

View File

@ -77,7 +77,10 @@ Finder
Form
----
* Using names for buttons that do not start with a letter, a digit, or an underscore leads to an exception.
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons leads to an
exception.
* Using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget` option is
set to `single_text` is not supported anymore.
* The `getExtendedType()` method was removed from the `FormTypeExtensionInterface`. It is replaced by the the static

View File

@ -63,6 +63,18 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
$this->name = $name;
$this->options = $options;
if (\preg_match('/^([^a-z0-9_].*)?(.*[^a-zA-Z0-9_\-:].*)?$/D', $name, $matches)) {
if (isset($matches[1])) {
@trigger_error(sprintf('Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated since Symfony 4.3 and will throw an exception in 5.0 ("%s" given).', $name), E_USER_DEPRECATED);
}
if (isset($matches[2])) {
@trigger_error(sprintf('Using names for buttons that do not contain only letters, digits, underscores ("_"), hyphens ("-") and colons (":") ("%s" given) is deprecated since Symfony 4.3 and will throw an exception in 5.0.', $name), E_USER_DEPRECATED);
}
}
// to be added in 5.0
// FormConfigBuilder::validateName($name);
}
/**

View File

@ -4,6 +4,10 @@ CHANGELOG
4.3.0
-----
* Using names for buttons that do not start with a letter, a digit, or an underscore is deprecated and will lead to an
exception in 5.0.
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons is deprecated and
will lead to an exception in 5.0.
* deprecated using the `date_format`, `date_widget`, and `time_widget` options of the `DateTimeType` when the `widget`
option is set to `single_text`
* added `block_prefix` option to `BaseType`.

View File

@ -28,7 +28,6 @@ class ButtonBuilderTest extends TestCase
['foo'],
['0'],
[0],
['button[]'],
];
}
@ -40,6 +39,14 @@ class ButtonBuilderTest extends TestCase
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder($name));
}
/**
* @group legacy
*/
public function testNameContainingIllegalCharacters()
{
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder('button[]'));
}
public function getInvalidNames()
{
return [