@@ -45,23 +45,29 @@ public function registerBundles()
45
45
46
46
## Configuration in Symfony 3
47
47
48
+ The configuration is the same as the following section, but the path should be
49
+ ` app/config.yml ` instead.
50
+
51
+ ## Configuration in Symfony 4 and up
52
+
48
53
If you do not explicitly configure this bundle, an HTMLPurifier service will be
49
54
defined as ` exercise_html_purifier.default ` . This behavior is the same as if you
50
55
had specified the following configuration:
51
56
52
57
``` yaml
53
- # app/ config.yml
58
+ # config/packages/exercise_html_purifier.yaml
54
59
55
60
exercise_html_purifier :
56
61
default_cache_serializer_path : ' %kernel.cache_dir%/htmlpurifier'
57
62
` ` `
58
63
59
- The ` default` profile is special in that it is used as the configuration for the
60
- ` exercise_html_purifier.default` service as well as the base configuration for
61
- other profiles you might define.
64
+ The ` default` profile is special, it is *always* defined and its configuration
65
+ is inherited by all custom profiles.
66
+ ` exercise_html_purifier.default` is the default service using the base
67
+ configuration.
62
68
63
69
` ` ` yaml
64
- # app/ config.yml
70
+ # config/packages/exercise_html_purifier.yaml
65
71
66
72
exercise_html_purifier:
67
73
default_cache_serializer_path: '%kernel.cache_dir%/htmlpurifier'
@@ -81,45 +87,12 @@ option to suppress the default path.
81
87
82
88
[configuration documentation] : http://htmlpurifier.org/live/configdoc/plain.html
83
89
84
- # # Configuration in Symfony 4 and up
85
-
86
- If you do not explicitly configure this bundle, an HTMLPurifier service will be
87
- defined as `exercise_html_purifier.default`. This behavior is the same as if you
88
- had specified the following configuration :
89
-
90
- ` ` ` yaml
91
- # config/packages/exercise_html_purifier.yaml
92
-
93
- exercise_html_purifier:
94
- default_cache_serializer_path: '%kernel.cache_dir%/htmlpurifier'
95
- ` ` `
96
-
97
- The `default` profile is special, it is *always* defined and its configuration
98
- is inherited by all custom profiles.
99
- ` exercise_html_purifier.default` is the default service using the base
100
- configuration.
101
-
102
- ` ` ` yaml
103
- # config/packages/exercise_html_purifier.yaml
104
-
105
- exercise_html_purifier:
106
- default_cache_serializer_path: 'tmp/htmlpurifier'
107
- html_profiles:
108
- default:
109
- config:
110
- Cache.SerializerPermissions: 777
111
- custom:
112
- config:
113
- Core.Encoding: 'ISO-8859-1'
114
- ` ` `
115
-
116
90
# # Autowiring
117
91
118
92
By default type hinting `\HtmlPurifier` in your services will autowire
119
93
the `exercise_html_purifier.default` service.
120
94
To override it and use your own config as default autowired services just add
121
- this in you `app/config/services.yml` in you use symfony 3 or `config/services.yaml`
122
- if you use symfony 4 :
95
+ this configuration :
123
96
124
97
` ` ` yaml
125
98
# config/services.yaml
@@ -131,7 +104,8 @@ services:
131
104
132
105
# ## Using a custom purifier class as default
133
106
134
- If you want to use your own class as default purifier, define a new alias :
107
+ If you want to use your own class as default purifier, define the new alias as
108
+ below :
135
109
136
110
` ` ` yaml
137
111
# config/services.yaml
@@ -141,10 +115,7 @@ services:
141
115
exercise_html_purifier.default: '@App\H tml\C ustomHtmlPurifier'
142
116
` ` `
143
117
144
- In such case, the custom purifier will use its own defined configuration,
145
- ignoring the bundle configuration.
146
-
147
- # ## Argument binding
118
+ # ## Argument binding (Symfony >= 4.4)
148
119
149
120
The bundle also leverages the alias argument binding for each profile. So the
150
121
following config :
@@ -170,11 +141,10 @@ public function __construct(\HTMLPurifier $galleryPurifier) {} // gallery config
170
141
# # Form Type Extension
171
142
172
143
This bundles provides a form type extension for filtering form fields with
173
- HTMLPurifier. Purification is done during the PRE_SUBMIT event, which
174
- means that client data will be filtered before binding to the form.
144
+ HTMLPurifier. Purification is done early during the PRE_SUBMIT event, which
145
+ means that client data will be filtered before being bound to the form.
175
146
176
- The following example demonstrates one possible way to integrate an HTMLPurifier
177
- transformer into a form by way of a custom field type :
147
+ Two options are automatically available in all `TextType` based types :
178
148
179
149
` ` ` php
180
150
<?php
@@ -213,7 +183,7 @@ This bundles registers a `purify` filter with Twig. Output from this filter is
213
183
marked safe for HTML, much like Twig's built-in escapers. The filter may be used
214
184
as follows :
215
185
216
- ` ` ` jinja
186
+ ` ` ` twig
217
187
{# Filters text's value through the "default" HTMLPurifier service #}
218
188
{{ text|purify }}
219
189
@@ -252,7 +222,7 @@ $builder
252
222
// ...
253
223
` ` `
254
224
255
- ` ` ` jinja
225
+ ` ` ` twig
256
226
{# in a template #}
257
227
{{ html_string|purify('custom') }}
258
228
` ` `
0 commit comments