04.
Actions Config
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.
21 Comments
Following along with the tut...
This...
... didnt work for me.
But this...
...did.
The docs show both approaches, but describes the first as "removing" the action and the second as "disabling" it. Seems to me that the disabled_actions did the trick and also didnt allow the hack you show in the vid. It gives me a juicy 403 error when I try it. I'm cool with the second approach just wanna make sure I'm understanding the usage.
BTW, thx for the vids. For the first time ever I feel like a grown-up developer and not just some hack gluing php thingys together. The OOP stuff has really clicked for me.
Yo jose!
Yea, you've nailed it. When you do
actions: [-show], it's superficial. With this, you should see the link disappear... but it's still totally accessible if you click on it. Withdisabled_actions... it's totally disabled. A juicy 403 error when you try to access it ;). I actually use both config by the end of the video (https://knpuniversity.com/screencast/easyadminbundle/actions#disabling-actions), but really, onlydisabled_actionsshould be necessary: it's the "stronger" of the two (if an action is disabled, there will of course not be any links to it).Translation, you're totally understanding things correctly! And I'm SO glad the dug the OOP tutorials! If that clicked... you are unstoppable. I remember when OOP clicked for me - it was one of the few programming things that I really just needed someone else to explain to me. It's a beautiful (& dangerous?) feeling.
Cheers!
FWIW... I have the same experience. The only thing that makes the "Show" action go away is to add the "disabled_actions: ['show']" line directly under the "SubFamily:" section in config.yml. The ["-show"] doesn't do anything no matter where it's located.
Hey Andy,
Thanks for sharing it with others. Probably EasyAdminBundle slightly changed its behavior in newer versions or just tweaked their templates, so the problem could be in overridden templates of EasyAdminBundle, if you have ones.
Cheers!
Hello SymfonyCast team! - didn't find a better place to write my question - so here it is: I'm trying to make a crud for my ProductSupply class with EasyAdmin, but the problem is that on details(show) of the ProductSupply i need to make a view of all ProductSupplyList objects(Associations) that belong to ProductSupply entity NOT as dropdown list, but as a form-list with ability to add/remove them like an index of some object in EA inside a show of parent object. Is it somehow possible? Would be grateful for any help)
Hey Andrejus,
So, you need to add a form on the "detail" page of ProductSupply that will help you to add/remove some items to the collections - yeah, sounds kinda complex :) I don't think there's something out of the box, as we're talking about detail page, not about new/edit page that is based on forms. You probably should think of be able to add those on the new/edit form, and on edit form you probably can make some fields read-only to avoid modifying them unintentionally. And then try to use custom form types, though I think it should work out of the box of EA as well. Or another solution would to override some templates and actions, specifically, you need to override detail.html.twig EA template and render a custom form on that page, probably somewhere below of the main content, so that you can leverage "{{ parent() }}" call to avoid overriding everything and just add your form below the parent content. Then, you can try to override detail() action... or probably better to send that form to a different new action that will handle it and redirect you back to the ProductSupply detail page. Or, you can even handle that form via fancy AJAX request to stay on the detail page, but it may be even more tricky, so it's up to you :)
I hope this helps!
Cheers!
Hey Victor,
It really is! I appreciate it. I managed to make a collection field in edit/new - but I can't find any info on few things. As i mentioned before I have a ProductSupply and ProductSupplyList Entities with a relationship OneToMany(mapped by productSupply). And used the custom form type, so now in my ProductSupply class i managet to generate a collection that is a ProductSupplyListType, but can't find out how I can define a productSupply field as a current ProductSupply that I'm in. And the second issue is when I'm trying to add to ProductSupplyLists(it's a collection field of ProductSupply entity) it doesn't save to db. Maybe I have an issue with a relation? Sorry for my bad English ((
Hey Andrejus,
Hm, it's difficult to say what may go wrong, you probably better debug things... Most probably you just need to persist those new entities in the collection in case you managed to render the form as you want with all the necessary fields. You can do it manually by overriding createEntity/persistEntity/updateEntity methods from the EA, depends on which page you're on. In those methods first of all you can debug if the entity looks ok and contains all the entities in the collection you sent in the form - if everything is ok, probably iterate over the collection and persist easy entity in the collection so that the flush method saves them in the DB. As a second alternative, you may want to add cascade persist for that collection in your mapping and Doctrine will automatically do that persisting.
I hope this helps!
Cheers!
Thx again Victor, I managed to figure that out and used cascade and added 'by reference' => false. Answers were really helpful. Have a nice day!
Hey Andrejus,
Ah, yes, "by_reference" form field option was also important here, good catch!
I'm happy to hear it was helpful ;)
Cheers!
Hi Ryan,
When I add the option "show" to the list view, I correctly see the link, but when I press it, I have a 500 error that I am not sure how to overcome.
The error says:
Variable "form" does not exist
in vendor/easycorp/easyadmin-bundle/src/Resources/views/default/new.html.twig (line 1)
Any idea on what might cause it?
Hey Alessandro,
Hm, interesting... what version of EasyAdmin do you have? This sounds like a bug, probably if you could upgrade to the latest EasyAdmin it will fix the problem. Or probably the variable was renamed to form but in your application it calls differently. Did you override any parts of EasyAdmin controllers? Did you pass any forms to it? It might be you just need to rename variable of the form you're passing to the template, or probable you just override some controllers but forgot to pass all the necessary variables?
I hope this helps!
Cheers!
I don't get get a SubFamily link in Show view. Only a plain div.
Hey Diaconescu
Could you show me your code? so I can help you debugging
Cheers!
Google for petre-symfony github. You'll see a link GitHub - petre-symfony/getting-crazy-with-form-themes. Follow the link. Go to repositories link. You'll see EasyAdminBundle-KNP-tutorial repository. Then go to branch 3.Actions_Config. Copy that branch if you want. Code until commit 43490721d44de584c5a40013b3347b9051f0d8d5 (Removing Actions)
Cheers.
Hey Diaconescu
You don't have a link to show action because you have it disabled in your configuration
https://github.com/petre-sy...
Cheers!
You speak about the lines
But they exist in commit 43490721d44de584c5a40013b3347b9051f0d8d5(Removing Actions) In commits before this one this lines doesn't exist so show action is allowed there. SubFamily link in Show view genus is also a link before disabling it.
Hey Diaconescu
I'm not sure why this is happening (I just checked your code and looks correct), I believe is something internal about the bundle, but updating it was not the answer, I'll keep digging to find a reason. If in the meanwhile you find the solution, let us know :)
Cheers!
Hey MolloKhan!
I found the problem - it's VERY small :). In your config, you have:
But, it should be:
Notice the capital F in SubFamily. Yes that's the problem! Actually, it's a mystery to me that this works at all! EasyAdminBundle must "correct" this somehow... because the SubFamily admin section DOES work. But, this small inconsistency was enough for the admin to think that there was no SubFamily section to link to. As soon as I changed the f to F, I got the link.
Btw, nice job following along with the tutorial! It looks like you're coding through really well :).
Cheers!
paypal unavailable in my country can i pay with Bitcoin ?
Hey Chahir Jbali!
Ah yes, sorry about that! Can you email us - hello@knpuniversity.com and tell us what country you are in? We can definitely work together to find something that works :).
Cheers!
"Houston: no signs of life"
Start the conversation!