16.
Adding a Custom Action
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.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
12 Comments
Hi guys, I have an issue.
When I set a new "resource" in easy_admin.yaml :
easy_admin_bundle:
resource: "@App/Controller/EasyAdmin/AdminController.php"
prefix: /easyadmin
type: annotation
Getting this Error:
An exception has been thrown during the rendering of a template ("Bundle "App" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your App\Kernel.php file? in @App/Controller/EasyAdmin/AdminController.php (which is being imported from "/var/www/site.loc/config/routes/easy_admin.yaml"). Make sure the "App" bundle is correctly registered and loaded in the application kernel class. If the bundle is registered, make sure the bundle path "@App/Controller/EasyAdmin/AdminController.php" is not empty.").
And the whole project doesn't work.
<b>official documentation:</b>
<a href="#">https://symfony.com/doc/master/bundles/EasyAdminBundle/book/complex-dynamic-backends.html</a>
<i>The default Symfony routing config loads first the annotations of controllers defined in src/Controller/. If you override the AdminController in that directory, the routing config defined in config/routes/easy_admin.yaml will be ignored. You can comment the contents of that file and use instead the @Route annotation of AdminController to configure that route.</i>
I changed the controller directory(src/Admin), but that didn't help either.
Any ideas what this could be?
And of course my controller:
`
namespace App\Controller\EasyAdmin;
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController as BaseAdminController;
class AdminController extends BaseAdminController
{
}
`
Hey @Igor
You just need to update the resource key value. It should point to your EasyAdmin controller(s) folder or file (depending if you pretend to have more than one controller to manage EasyAdmin actions) and it should work
Cheers!
Hello there !
Firstly, a huge thanks for this gorgeous cast ! :)
I'm actually building a custom form in which there are custom fields that contains 2 thing :
a list of entity to link to the main entity
a form to add a new entity that will be listed when registered
i do have 3 of those (and one of them contains itself a couple of those).
looks like:
MainForm
- normal fields
- custom field 1 :
---- entitylist1
---- customFieldForEntitylist1
- custom field 2 :
---- entitylist2
---- customFieldForEntitylist2
- custom field 3 :
---- entitylist3
---- customFieldForEntitylist3
------- entitylist4
------- customFieldForEntitylist4 (inside customFieldForEntitylist3)
Form End
(if it's not clear enough i'll add a link to a picture)
My actual problem is when i submit the main form, i don't have those custom data.
So i tried submiting using your 'custom action' (genus_feed) and i don't have any data at all...
Is there a way to 'customize' the basic EasyAdmin insertEntity so i can there use my custom data fields ?
thanks again :D
Hey @Duri3l
Looks like you are already a pro on EasyAdmin! Congrats!
Thanks for sharing your case and solution to others
Cheers!
Thanks !
I must say i'm trying to do something nice and tidy for about 2 or 3 week so... i'm starting to get some clues on what's going on :P
Now i'm ok with both new and edit form, but i changed a bit my database : an adress can be "owned" by many users, but only one adress at a time can be the "primary adress" for a user. I just don't really know how i can design the form for this...
I first had a thought about a list whith checkbox to add adress for this user, and a couple radio to set them all "notPrimary" except for one, but i'm pretty sure this will be real big and ugly if i have a couple hundred adress in database... So i don't really know how i can do this...........
if you have any idea about this, i'd be happy :D
Did it a bit after i said it there....
i did add a js event listener on the adress select change (and call it on page load if it is edit page) to get all adress selected and add them in another select (right under it) so i can select One (and only one) adress to be the primary adress for this user !
it's fully functionnal now, just need to implement password encryption and some other stuff (like email validation and every little functionnality like these) and i'll be good for this one ^^
Nice job! You've been beating us to replying :). Thanks for posting all of your solutions - I'm sure it will be helpful to others!
Hem, i forgot...
I'm using 'normal forms' to feed my database with each other entities so... Can i tell EasyAdmin to use a custom Controller only for this custom entity form and only this one ?
I finally found what i was looking for. I did put the entity controller in easy_admin.yaml and then i customized the new action so it is now a route (user_new), then i created a route named user_new and inside it i call
return $this->executeDynamicMethod('render<entityname>Template', array('new', $this->entity['templates']['new'], $parameters));
so i do have my customized template and all that goes within.
Then inside this same function i check if the form is set and valid, and if it is i grab all the info i need and i put it into my new entity.
Here it shows how to add a new action button, but I would like to know how to remove the delete button action when I'm editing a record from an entity. I already deactivate the delete button from the list of items from the entity as it shows in the video number 9 "Dynamically Remove the delete Action Link" but if I still having this button when I edit is not useful at all. Thank you for advance!
Hey Apr
If what you want is to disable the "delete" action entirely for an entity, then you can do it by specifying that action as disabled
If not, then you will have to remove the action from the "edit" action as well (just as you did it for the "list" action)
Cheers!
Thank you very much! the config parameter was enough! :)
"Houston: no signs of life"
Start the conversation!