Skip to content

Commit

Permalink
feature #28969 [Form] deprecate using invalid names for buttons (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Form] deprecate using invalid names for buttons

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #28964
| License       | MIT
| Doc PR        |

Commits
-------

405aa54 deprecate using invalid names for buttons
  • Loading branch information
fabpot committed Feb 21, 2019
2 parents 5c73900 + 405aa54 commit 02d6c0f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions UPGRADE-4.3.md
Expand Up @@ -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.

Expand Down
5 changes: 4 additions & 1 deletion UPGRADE-5.0.md
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/Form/ButtonBuilder.php
Expand Up @@ -63,6 +63,18 @@ public function __construct(?string $name, array $options = [])

$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);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Expand Up @@ -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`.
Expand Down
9 changes: 8 additions & 1 deletion src/Symfony/Component/Form/Tests/ButtonBuilderTest.php
Expand Up @@ -28,7 +28,6 @@ public function getValidNames()
['foo'],
['0'],
[0],
['button[]'],
];
}

Expand All @@ -40,6 +39,14 @@ public function testValidNames($name)
$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 [
Expand Down

0 comments on commit 02d6c0f

Please sign in to comment.