-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #39 Improved the way entity fields are displayed in listings …
…and forms (javiereguiluz) This PR was squashed before being merged into the master branch (closes #39). Discussion ---------- Improved the way entity fields are displayed in listings and forms ### The problem we want to solve EasyAdmin must work right out of the box. Listings and forms should display any entity field correctly, regardless how wrong those properties are defined. ### The issues we're facing In an ideal world, Doctrine entities would be well defined and would contain no errors. In that ideal world, we could use some simple Twig code to display those entity properties in forms and listings. However, lots of applications contain errors in Doctrine entities, such as declaring a property `protected` and not providing any `getter` method to access its value. In those cases, Twig would display these awful error messages and EasyAdmin would crash: ![twig_error](https://cloud.githubusercontent.com/assets/73419/5792319/55e84c46-9f13-11e4-9961-930d1c0d9360.png) ### How I propose to solve them Twig is great when things go right. But Twig is very weak for "defensive programming". That's why I propose to move all the logic used to display entity fields to a custom Twig extension. If you check the code of the extension included in this PR, you can see that performs a lot of "safeguard actions" to never throw an error: `try ... catch`, `reflection`, `null` and `instanceof` checks, etc. In my local tests, the results are very promising, because the application now never crashes: **Simple associations are linked to their "show" action and null values are not a problem** ![simple_associations_and_null](https://cloud.githubusercontent.com/assets/73419/5792324/f1b7449c-9f13-11e4-9f1b-65ba75d503ac.png) **Null property values are no longer a problem** ![null_properties](https://cloud.githubusercontent.com/assets/73419/5792325/f81c7730-9f13-11e4-99be-0f591e2ad55d.png) **When an association is a collection, we display the number of elements included in the collection** ![association_collections](https://cloud.githubusercontent.com/assets/73419/5792331/166dafec-9f14-11e4-9d47-5e654edf99f7.png) **The worst case scenario: a property without a getter and non-public** ![innaccessible_properties](https://cloud.githubusercontent.com/assets/73419/5792333/24be3562-9f14-11e4-8c2e-4d4a10eb78db.png) They even include a help message explaining why they are inaccessible: ![innaccessible_properties_help_message](https://cloud.githubusercontent.com/assets/73419/5792335/3129ad7c-9f14-11e4-83e3-ae868774ebaf.png) By the way, this PR fixes #24, #23 and #5. Commits ------- a1e1880 Improved the way entity fields are displayed in listings and forms
- Loading branch information
Showing
7 changed files
with
218 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" ?> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
|
||
<service id="easyadmin.twig.extension" class="JavierEguiluz\Bundle\EasyAdminBundle\Twig\EasyAdminTwigExtension" public="false"> | ||
<argument type="service" id="router"></argument> | ||
<tag name="twig.extension" /> | ||
</service> | ||
|
||
</services> | ||
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.