Field Rendering

This Chapter isn't
quite ready...

Rest assured, the gnomes are hard at work
completing this video!

Browse Tutorials

Coming soon...

As we have talked about the configure fields controls both how the fields are rendered on the list page, but also how they're rendered on the form pages. And that leaves us with a situation that is not for example, we don't want an ID field on our form. We only wanna render it on the index page. So to fix that we can call there's a bunch of really useful methods on these field of classes. For example, we can call only on index And just like that it's gone from the form page, but we still have it on the index page. And as you're playing with these methods, I want to invite you to kind of dive in and see the code behind the scenes. That's gonna help you understand easy admin better. So for example, if I held command or control and click into only index jumps us into this thing called field trait, this is a, a trait that's shared by all fields. And you can see something like this arrow, DTO->set displayed on, You know what no, what let's not show that.

So methods like only on index are gonna give us lots of control, but also notice that configure fields is past the page name. That'll be like index or detail or edit. So at the end of the day, you can always just put if statements inside of here and, uh, dynamically return or don't return different things from this method. All right. So the other problem on our form is that we have this full name method in the database. We have a first name, field, and a last name field. So it's kind nice to be able to render them as a full name on the index page. But ultimately when we go to the form, we probably wanna control their first name in last name separately. And this won't even work if I submit this right now. Well actually, if I change something and then submit it, I get an error. It says, can I determine access type for property full name? Because inside of our user class, I have a get full name, but I don't have a set full name and I don't want one. So the point is that over inside a configure fields, we can take that configure full name and say, only on index. Now we're gonna have full name on our index, but we don't have full name on our form.

And actually instead of only on index, we can instead use hide on form. The difference being that full name will now show on the details page. So if I go back to users and click show to go to the details, page full name is still included on there. So you can see there's lots of different ways to play with these fields to get 'em in just the right spot. All right. So now that full name's gone from the form. We need to put first name and last name back. So let's say yield and I'll just use the lazy field call, call new way.

First name, last name that we'll get it to show up here perfectly then back on the list page, we don't want those. You guys know what to do. So there's a nice little method for this called only on forms. So I'll copy that and repeat that for last name and now perfect. Then finally, I'm gonna do the same thing for created at I like having created at, on the list. I do not like having created at inside of the form because that's really supposed to be set automatically. Sit down here. We will say hide on form, be beautiful. So that was fairly easy and fairly simple. Next, I wanna dive a little bit further into the fields. We're gonna take one of these fields and configure its form type in a different way. Now, as we do, we're gonna learn about a concept called field configurator.

Leave a comment!

What PHP libraries does this tutorial use?

// composer.json
    "require": {
        "php": ">=8.0.2",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "composer/package-versions-deprecated": "^1.11", //
        "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.0.1
        "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