Chapters
40 Chapters
|
4:19:16
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
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!
16.
Field Configurator Logic
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.
This tutorial is built on Symfony 6 but works great on Symfony 7!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2.0",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "^1.11", // 1.11.99.4
"doctrine/doctrine-bundle": "^2.1", // 2.5.5
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.2.1
"doctrine/orm": "^2.7", // 2.10.4
"easycorp/easyadmin-bundle": "^4.0", // v4.0.2
"handcraftedinthealps/goodby-csv": "^1.4", // 1.4.0
"knplabs/knp-markdown-bundle": "dev-symfony6", // dev-symfony6
"knplabs/knp-time-bundle": "^1.11", // 1.17.0
"sensio/framework-extra-bundle": "^6.0", // v6.2.5
"stof/doctrine-extensions-bundle": "^1.4", // v1.7.0
"symfony/asset": "6.0.*", // v6.0.1
"symfony/console": "6.0.*", // v6.0.2
"symfony/dotenv": "6.0.*", // v6.0.2
"symfony/flex": "^2.0.0", // v2.4.5
"symfony/framework-bundle": "6.0.*", // v6.0.2
"symfony/mime": "6.0.*", // v6.0.2
"symfony/monolog-bundle": "^3.0", // v3.7.1
"symfony/runtime": "6.0.*", // v6.0.0
"symfony/security-bundle": "6.0.*", // v6.0.2
"symfony/stopwatch": "6.0.*", // v6.0.0
"symfony/twig-bundle": "6.0.*", // v6.0.1
"symfony/ux-chartjs": "^2.0", // v2.0.1
"symfony/webpack-encore-bundle": "^1.7", // v1.13.2
"symfony/yaml": "6.0.*", // v6.0.2
"twig/extra-bundle": "^2.12|^3.0", // v3.3.7
"twig/twig": "^2.12|^3.0" // v3.3.7
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.4.1
"symfony/debug-bundle": "6.0.*", // v6.0.2
"symfony/maker-bundle": "^1.15", // v1.36.4
"symfony/var-dumper": "6.0.*", // v6.0.2
"symfony/web-profiler-bundle": "6.0.*", // v6.0.2
"zenstruck/foundry": "^1.1" // v1.16.0
}
}
14 Comments
Tip: For an app where you need to display dates & times to users in different time zones, you can use a field configurator for datetime fields to set the "view_timezone" option. The "setTimezone()" method only affects the index/detail views, but for forms, in order for users to be able to input the times in their own timezone, you have to set the view_timezone form type option. Using a field configurator prevents you from having to set that on every single datetime field in the backend.
There are also Filter Configurators.
Thank you for sharing it @Nick-F
Cheers!
Hi!
How do you know that this tag =
ea.field_configurator? And how to know the tag of our service?Hey Ruslan,
You can leverage
bin/console debug:containerSymfony command by passing a service name as an argument. E.g., if you run:To see info about the
ArrayConfiguratorservice - it will show you in the output that itea.field_configuratortag.Also, another useful command would be
bin/console debug:container --tagsthat will print all tags and related to them services.I hope this helps!
Cheers!
Can you tell me what is u() function in TruncateLongTextConfigurator.php ?
PHPOStorm show mi message: Undefined function 'u' :)
And Symfony show: Attempted to call function "u" from namespace "App\EasyAdmin".
Hey Lechu, I believe you forgot to add this use statement after installing the string component
use function Symfony\Component\String\u;The string component helps handle Unicode strings and other encoding formats. You can learn more about it here: https://symfony.com/doc/current/components/string.html#what-is-a-string
i installed string componet but it stil; not work :)
I used this command: composer require symfony/string
Hi just wanted to point out, when running
<br />symfony console debug:container --tag=ea.field_configurator<br />or simply
<br />symfony console debug:container<br />I get the following error in my terminal :
In CheckDefinitionValidityPass.php line 59:
The definition for "tags" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.
Any idea where this is coming from? TIA.
Oups, my bad, wrong indentation in services.yaml was causing the issue !
Hey Estelle G.
Nice that you found how to solve issue ;)
Keep learning! Cheers!
FYI, I <i>believe</i> the
AsTaggedItemattribute can be used for theTruncateLongTextConfiguratorclass to avoid adding it in yourservices.yaml:#[AsTaggedItem('ea.field_configurator', -1)].Hey Kevin B.
Yes, you're right, thanks for bringing this up. I think that's just matter of taste of how you like to handle this config stuff. My advice here is to pick one style and be consistent throughout the source code.
Cheers!
Made a mistake above, the first argument of AsTaggedItem is the "index by" not the tag name. The tag name should already be autoconfigured so the correct usage of the attribute is (I believe):
#[AsTaggedItem(priority: -1)].Yeah, I got confused too. If you want to define the tag of a class using PHP attributes you need to use the
AutoconfigureTagattributeCheers!
"Houston: no signs of life"
Start the conversation!