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!
18.
Creating a Custom Field
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
}
}
16 Comments
Hi everyone
I have project that has the latest version of EasyAdmin, and I use PostgreSQL.
My problem is the following: I have imported some data in one of my tables directly from an older database to the database that I use in this project. The result is: I can't insert new record from EasyAdmin. The error that I get is:
As I have read, the issue is in the way how PostgreSQL manage the primary keys. As far as I have understand, I have now to provide the latest id + 1 to the form. While I guess that I have now to add new hidden field in the insert new action, I have no idea which method I have to override in my SkillCrudController so I can add somehow add (I am now guessing) hidden field and the value for the id? Again, I am guessing here...please correct me if I am wrong.
Cheers
Hey @t5810
I believe you need to fix your DB table instead of changing how your app determines the ID. I leave you here a SO post that may help you out https://stackoverflow.com/questions/244243/how-to-reset-postgres-primary-key-sequence-when-it-falls-out-of-sync
Hope it helps. Cheers!
Hi MolloKhan
Brilliant. Works like a charm now Thank you very much!
Cheers
Hello,
My project is using EasyAdmin v.3.5.16 and Symfony v5.3.15. I have a description field which is a TextEditorField. I am wanting to either configure this field, add a custom type or some other solution in order to have this description field have 'Source' WYISWYG option to toggle HTML formatting. I've been looking and and seems Trix Editor doesn't have this option? Perhaps installing FOSCKEditorBundle would be best to accomplish this? Looking for some advice/direction on how best to have Rich Text field with a 'Source' option. Thank you in advance.
Hey Brent,
Yeah, unfortunately, the built-in
TextEditorFielddoes not have this option. So, the best would be to create a custom field and attach a more advanced JS WYSIWYG editor like CKEditor you mentioned. Or TinyMCE is another popular WYSIWYG editor with the source code option, but there're a lot of others too, so just use your favorite.Well, as a workaround, you may try to add some JS that will toggle the TrixEditor/textarea. If you inspected the code - you would see that the textarea is hidden nearby that editor with
display: noneCSS prop. So, in theory, you can add a link with some custom JS code attached to it to hide the editor and show that textarea - it might be a nice and simple solution, but you would need to find a way to sync the changes in the source code (i.e. textarea) back with the TrixEditor if you need it - there should be a way I think, but I've never tried it myself, so can't tell you for sure :)I hope this helps!
Cheers!
Hi,
In my index page, i would like to create an editable field (or dropdown list). It's for a votation dances. I imagine the same logic than a boolean field that's update database.at each change.
Can you help me to do that?
Have a good day
Alain from France
Hey Delenclos-A ,
Unfortunately, nothing is available out of the box in EasyAdmin for this, so you literally would need to write a custom field for this and add some javascript code to make it work. Probably you could re-use some other JS lib for the modern dropdown list (e.g. https://select2.org/ ), etc.
This chapter should give you a good start with the EA custom field creation, but you would need to add some JS code to it to make it actually work. You can add a custom JS code via
addJsFiles()or viaaddWebpackEncoreEntries()in case you're using Webpack Encore - similar toaddCssClass()that we're using in this video.You can also take a look at the core
BooleanFieldto see how it works. It seems like you would also need to create a custom endpoint to which you will actually send the AJAX request and handle the field value change.I hope this helps!
Cheers!
Thank’s team for your help, I’ll try this in everything month, because my own logic for votation is complex (you have some points to give, all of them must be given) and it’s not easy to do that for my old head. Maybe an unmapped field… for the moment i try this in a simple controller. Thank’s again and have a good day.
Hey Delenclos-A,
I hope those ideas will be useful! Try to watch this course till the end, it should give you understanding of more things that you can do in EA, and better understand the EA.
I hope this will help!
Cheers!
Hi, worth every Euro! But I'm stuck in creating a custom template for showing message 1 of x. The messages are in a message_group. In the message Entity I can do this.
But it would be better to do this in a custome easyAdmin twig template.. but how can I get this total message count in the template ?
number of replies om posts is commonly there ... eg reply 1 of 10 .. Can't find it..
Hey HJT,
You'll need to create a custom field template. This video may help you out https://symfonycasts.com/screencast/easyadminbundle/field-template
or perhaps this other video https://symfonycasts.com/screencast/easyadminbundle/override-template
Cheers!
Hello! I just wondering, why the Fields (IntegerField, TextField, etc.) are all marked as final classes? Let's say I want to have an own IntegerField which I use everywhere, with inheritance I just could extend the IntegerField, override the static "new"-method, but the Configurator-system would still work in the background. But why this is not allowed :-D? Thanks!
Hey Szabolcs,
This is a good question. Unfortunately, I’m not a maintainer of this bundle and you probably better to ask it in the repository of this bundle, or ask a question there if you want the exact reason behind of it.
Though I think I can give you hints why it might be done this way :) the real problem is in maintenance I think. Making some classes final unload the maintainer, ie the maintainer can easily change the code inside those clases without worrying about BC brakes. In turn, it allows easier to make new minor releases instead of making major ones that would contain BC brakes. Moreover, another important thing is that fields are simple, you can easily write a new standalone field, and if you want - just copy/paste the existent code from the core classes. That’s in my opinion and I hope it helps, but if you really curious - you can ask maintainers I think :)
Cheers!
ok, thank you very much for the answer!
You're welcome! :)
By the way, of course I can write a custom factory-class, which can create my IntegerField and the Configurator-system would work, I am just curious about the idea, to mark all Field-classes as final classes.
"Houston: no signs of life"
Start the conversation!