Chapters
41 Chapters
|
4:45:40
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: ^7.1.3
Subscribe to download the code!Compatible PHP versions: ^7.1.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
20.
Form Theme Block Naming & Creating our Theme!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.10.2
"doctrine/doctrine-bundle": "^1.6.10", // 1.10.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.7.2
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knplabs/knp-paginator-bundle": "^2.7", // v2.8.0
"knplabs/knp-time-bundle": "^1.8", // 1.8.0
"nexylan/slack-bundle": "^2.0,<2.2.0", // v2.0.0
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.0
"sensio/framework-extra-bundle": "^5.1", // v5.2.1
"stof/doctrine-extensions-bundle": "^1.3", // v1.3.0
"symfony/asset": "^4.0", // v4.1.6
"symfony/cache": "^3.3|^4.0", // v4.1.6
"symfony/console": "^4.0", // v4.1.6
"symfony/flex": "^1.0", // v1.21.6
"symfony/form": "^4.0", // v4.1.6
"symfony/framework-bundle": "^4.0", // v4.1.6
"symfony/property-access": "^3.3|^4.0", // v4.1.6
"symfony/property-info": "^3.3|^4.0", // v4.1.6
"symfony/security-bundle": "^4.0", // v4.1.6
"symfony/serializer": "^3.3|^4.0", // v4.1.6
"symfony/twig-bundle": "^4.0", // v4.1.6
"symfony/validator": "^4.0", // v4.1.6
"symfony/web-server-bundle": "^4.0", // v4.1.6
"symfony/yaml": "^4.0", // v4.1.6
"twig/extensions": "^1.5" // v1.5.2
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.0", // 3.0.2
"easycorp/easy-log-handler": "^1.0.2", // v1.0.7
"fzaninotto/faker": "^1.7", // v1.8.0
"symfony/debug-bundle": "^3.3|^4.0", // v4.1.6
"symfony/dotenv": "^4.0", // v4.1.6
"symfony/maker-bundle": "^1.0", // v1.8.0
"symfony/monolog-bundle": "^3.0", // v3.3.0
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.1.6
"symfony/stopwatch": "^3.3|^4.0", // v4.1.6
"symfony/var-dumper": "^3.3|^4.0", // v4.1.6
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.1.6
}
}
9 Comments
Hi,
I have a problem with theme block code actually I have duplicate validation errors:
`
{%- block form_row -%}
{%- endblock form_row -%}
`
I searched for symfony documentation <a href="https://symfony.com/doc/current/form/form_customization.html#form-form-view-variables">https://symfony.com/doc/current/form/form_customization.html#form-form-view-variables</a> and I find next:
remove
{{- form_errors(form) -}}from form_row block and add it above form_row(s) rendering like:`
{{ form_start(registrationForm, {
`
This code works for me and it doesn't have duplicated validation error messages.
I am using to Symfony 5.1 and "symfony/form": "5.1.*".
My question: Am I doing something wrong and what is explanation for duplicate error messages.
@Vladimir Žarčanin,
Hey that looks weird. It shouldn't be duplicated in this case. Can you create a gist with related files or maybe github repo for more information?
Cheers!
Same here ;)
This happens because the errors are rendered on every form_label and not on the form_row.
Not sure if this has changed since in the bootstrap_4_layout.
Just remove the error rendering from the custom override.
That sounds very possible - thanks for posing the solution elkuku :).
Actually while following the tutorial and digging through the symfony docs I found a big red note here: https://symfony.com/doc/cur...
I love documentation :D :D :D
"There is a password_widget block but, when the label is being rendered, there is not a password_label block."
How does it know that it needs password_label block?
In here I dont see:
`{%- block password_widget -%}
{%- endblock password_widget -%}
`{%- block form_widget_simple -%}
{%- endblock form_widget_simple -%}`
Hey Lijana Z.!
Sorry for the slow reply!
Good question :). Here's what the process looks like internally:
A) The form system starts to render the "label" for a "password" field. It asks: "which block should I use to render this"?
B) To determine that, it first looks for a block called "password_label". It always first looks for a block that is the "field type" an underscore and then "label" (because it's rendering a label). For example, when the form system needs to render the label for a "textarea" it also looks for textarea_label first. By default, pretty much no field types have a custom "TYPE_label" block.
C) Because there is no "password_label" block, the form system automatically then looks for "form_label". That's just how the system works - it always falls back to using "form".
This is a slight over-simplification, but the general idea is accurate: it looks for password_label first and if it is not found, falls back to form_label. The reason you don't see this logic inside the
form_widget_simpleorpassword_widgetblocks is that the logic lives one level higher: this logic lives at the layer that is responsible for rendering the blocks. It's a crazy function, but the logic that renders the blocks and has all this "fallback logic" is this one: https://github.com/symfony/symfony/blob/b1bee601197e2a07ef3fd3274e46231b26e28824/src/Symfony/Component/Form/FormRenderer.php#L130Cheers!
thanks
"Houston: no signs of life"
Start the conversation!