diff --git a/README.md b/README.md index 33bc7c1..18898fb 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,11 @@ return [ ## Features -- [Rate Limiter Attributes](#rate-limiter-attributes) -- [Form Text Fields Empty String](#form-text-fields-empty-string) +- [Apply rate limiters using attributes](#apply-rate-limiters-using-attributes) +- [Use empty strings by default on text-based form fields](#empty-string-default-for-text-based-form-fields) +- [Set various attributes on <form> elements](#set-attributes-on-form-elements) -### Rate Limiter Attributes +### Apply rate limiters using attributes The bundle provides PHP attributes that can be used to apply the Symfony Rate Limiter component. @@ -83,7 +84,7 @@ headsnet_symfony_tools: Thanks to [this JoliCode article](https://jolicode.com/blog/rate-limit-your-symfony-apis) for the inspiration! -### Form Text Fields Empty String +### Empty string default for text-based form fields By default Symfony uses `null` as the default value for text-based form fields. This results in `null` values being all over the codebase. @@ -97,8 +98,20 @@ This is an opinionated solution, so must be enabled in the bundle configuration: ```yaml headsnet_symfony_tools: forms: - default_empty_string: - enabled: true + default_empty_string: true +``` + +### Set attributes on <form> elements + +The bundle provides an easy way to globally set attributes on `
` elements. + +These must be explicitly enabled in the configuration. + +```yaml +headsnet_symfony_tools: + forms: + disable_autocomplete: true # autocomplete="off" + disable_validation: true # novalidate="novalidate" ``` ## License diff --git a/src/HeadsnetSymfonyToolsBundle.php b/src/HeadsnetSymfonyToolsBundle.php index 4d13981..1c015e7 100644 --- a/src/HeadsnetSymfonyToolsBundle.php +++ b/src/HeadsnetSymfonyToolsBundle.php @@ -25,9 +25,7 @@ public function configure(DefinitionConfigurator $definition): void ->arrayNode('forms') ->addDefaultsIfNotSet() ->children() - ->arrayNode('default_empty_string') - ->canBeEnabled() - ->end() // End default_empty_string + ->booleanNode('default_empty_string')->defaultFalse()->end() ->booleanNode('disable_autocomplete')->defaultFalse()->end() ->booleanNode('disable_validation')->defaultFalse()->end() ->end() @@ -40,9 +38,7 @@ public function configure(DefinitionConfigurator $definition): void * @param array{ * root_namespace: string, * forms: array{ - * default_empty_string: array{ - * enabled: bool - * }, + * default_empty_string: bool, * disable_autocomplete: bool, * disable_validation: bool, * }, @@ -58,7 +54,7 @@ public function loadExtension(array $config, ContainerConfigurator $container, C ->set('headsnet_symfony_tools.rate_limiting.use_headers', $config['rate_limiting']['use_headers']) ; - if ($config['forms']['default_empty_string']['enabled']) { + if ($config['forms']['default_empty_string']) { $container->services() ->set('headsnet_symfony_tools.forms.default_empty_string_extension') ->class(TextTypeDefaultStringExtension::class) diff --git a/tests/Fixtures/config.yaml b/tests/Fixtures/config.yaml index cba8fe5..8b6fe74 100644 --- a/tests/Fixtures/config.yaml +++ b/tests/Fixtures/config.yaml @@ -1,8 +1,7 @@ headsnet_symfony_tools: root_namespace: App forms: - default_empty_string: - enabled: true + default_empty_string: true disable_validation: true disable_autocomplete: true rate_limiting: