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!
07.
Configuring Fields
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!
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
}
}
28 Comments
Hi. I have a message : The media could not be loaded, either because the server or network failed or because the format is not supported.
Hey Sébastien J.!
Thanks for reporting that! I have no idea what went wrong, but I basically "refreshed" the video on our end, and it seems to be working now. Please let me know if you still have any problems!
Cheers!
Please note that we started adding docs for Fields recently. That's why some fields are still undocumented. Sorry about that. The good thing is that if you use PhpStorm, you get autocompletion for all options, because they are just methods that you call on each field object.
Here's the list of field types: https://symfony.com/bundles...
We hope to finish the docs for all fields soon.
Hey Javier,
That's awesome news! Yeah, most fields are clear base on their names, but having more detailed docs on them will definitely help newcomers. And yeah, PHP autocompletion helps a lot too.
Thanks for the head ups :)
Cheers!
Yay PHP config!!!
In case anyone else has trouble finding the EasyAdmin documentation icon, it was removed from the Profiler bar in EasyAdmin 4.4.2 per this issue:
https://github.com/EasyCorp/EasyAdminBundle/pull/5453So.. if you're using 4.4.2 or later, just click anywhere in the Profiler to open it full screen and then look for the new EasyAdmin button near the bottom of the sidebar. There are now several links including one for documentation.
Hey CDesign,
Thank you for raising this up and providing the link to the PR that explains the reasons behind of this change. Yeah, it makes sense
Cheers!
In documentation for fields i missing info for choicetype, i'm not
sure how to deal with roles to be assigned from easyadmin, and encode
new password for user. Another one, upload some files from easyadmin?
Would we find something later on about that kind of stuff in this course?
Hey Hubert,
Yes, it will be covered a bit later in this course, so stick with us :) For now, it's more like simple field rendering and acquaintance with field types :)
Thank you for your patience!
Cheers!
Hello, I have tried to use the CodeEditorField. In the Crud-Controller in the method configureFields I wrote the following:
As a result, I get a simple textarea field on the admin page. The syntax highlighting does not work. Do I have to do something extra? I use EasyAdmin 4 with Symfony 7
Best regards and thanks in advance
Hey Eduard,
Yeah, most probably you also need to execute
bin/consoel assets:installcommand. I think that should do the trick and make some JS available for you. If still nothing, check the Console tab in the Google Chome dev tools, I bet it contains some errors that may hint you what else you need to do.Cheers!
Thank you very much for the quick reply.
I have just found the cause. The code fields are inside a CollectionField. I had to add the entries for CSS and JS files from CodeEditField to the CollectionField so that the testarea is replaced by the code editor. I should watch this SymfonyCast more carefully ))
This code solved the problem:
Hey Eduard,
I'm glad to hear you found the problem! And thanks for sharing the solution with others :)
Cheers!
Hi,
I'm using EasyAdmin 3.x, and I'm having issues with TExtEditorField; apparently, it strip all tags that are not div or H1; I need to handle H2, H3, etc ....
I have found this solution:
But it works only on EasyAdmin 4.x. Does Someone know some tricks to add other html tags mamagement?
Thanks in advance
Hey Gianluca-F,
Did you try this code in your EA 3 version? It might work I suppose because I see that v3 still has support, though it might be only security fixes support though. But it does not work - not sure then, try to ask this question on the bundle's repo, maybe someone who tried this will give you some tips how to achieve it, because I can't give you any tips about it, never do this before.
But if it does not work out of the box with the. TextEditorField - I'd recommend you to use simple TextField and attach any JS editor you love to it, you can easily add JS fields to specific CRUD controllers.
Cheers!
Hi Victor,
I have installed CKEditorBundle, I have created a new CustomField that use CkEditorType and I'm using it; it is awsome and works like a charm :-)
Thanks !
I have installed CKEditorBundle - ran the configuration but still cannot get it to display - going out my mind here :/
try to add these lines to
config/packages/fos_ckeditor.yamlHi GianLuca finally managed it, after installing CK Editor bundle & installing it I created a new Custom Field class called ContentField
And then in my PagesCrudController added configureCrud function to call my twig template
And finally called the CustomField I created above in the configureFields function
Hey Paul,
Well done! And thanks for sharing your solution with others, it might be helpful :)
Cheers!
Hey Gianluca-F,
That's awesome! And thank you for letting us know that it works for you well this way, I bet some users might be interested in it as well :) Yep, EA has some tools out of the box, but sometimes you can do extra work to make it even better for your project like with the CKEditor integration you made, well done!
Cheers!
Hello there,
How could I display computed fields in index view ?
I can't simply use a getter in my entity.
I need my entity data AND using my entity manager, but I can't find a way to do that.
By example, what I would like to do:
DateField::new('myEntityDate', 'date')
->formatValue(function ($value) use ($helper) {
return $helper->someFunction($entity, $value);
}),
In my closure, I've no way to access "$entity", or at least I've not found any. This is pretty annoying.
And injecting my helper in my entity class is bad practice.
Any idea ?
Autoresponding myself :)))
The solution is:
DateField::new('myEntityDate', 'date')
->formatValue(function ($value, $entity) use ($helper) {
return $helper->someFunction($entity, $value);
}),
The second parameter of the closure seems to be the entity object.
Hey Kershin
Yep! You're right, the second argument of the closure gives you the entity, but be aware that the $entity argument may be null, so you may want to code defensively
Cheers!
Hello Diego !
Thanks for your answer.
In which case the $entity argument could be null ? (in index & detail views)
Regards,
Hello,
I want to ask how to manage this situation. I have two fields A and B defined on Entity as nullable=true.
But I need to make one of them (A or B) required.
For example: When users writes some value to field A, field B should be empty. When users wtites some value on field B, field A should be empty.
Thank you for reply
Hey Tomáš S.!
Ah, then this is a "validation" trick: you need to make sure that you show the user a validation error if A & B are empty OR if A & B are both NOT empty. This actually has nothing to do with EasyAdmin, which is great! EasyAdmin simple "runs your entity's validation rules". And so, if we can get the validation rules setup on your entity correctly, it will just work :).
For this, I would use the Callback constraint: https://symfony.com/doc/cur...
This allows you to write a function in your entity that contains the exact validation logic you need. The only thing you'll need to decide is which field to attach the error to (field A or field B) in case they have filled out neither or both.
Let me know if this helps :).
Cheers!
"Houston: no signs of life"
Start the conversation!