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!
34.
Dynamic Disable an Action & AdminContext
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
}
}
7 Comments
Hello! I have a question. I've set up a redirect in Apache2 to force HTTP to HTTPS, and it's working correctly on all pages except for the 'Action::BATCH_DELETE' operation in EasyAdmin. The confirmation message in JavaScript still loads over HTTP, even though my Apache2 server is redirecting to HTTPS.
Hey @Lubna!
Hmm, I'm not sure, but I can maybe give you some hints. First, if you hover over the batch "Delete" button, it should actually be a link. And you should be able to see what its
hrefis. For me locally, I can see it usinghttps- e.g.https://127.0.0.1:9042/admin?crudAction=batchDelete&crudControllerFqcn=App%5CController%5CAdmin%5CQuestionCrudController&menuIndex=1&referrer=https%3A%2F%2F127.0.0.1%3A9042%2Fadmin%3FcrudAction%3Dindex%26crudControllerFqcn%3DApp%255CController%255CAdmin%255CQuestionCrudController%26menuIndex%3D1%26signature%3DkGiR2utacgViW5rXcNgjhu4MgM4iBEqS0wvR-4z7Om8%26submenuIndex%3D-1&signature=WqOjnSdbhGUubOwTpwa_WYmlCO3NGdE873qkbSVIgQY&submenuIndex=-1I wonder if this URL is http or https for you? I believe there is some JavaScript that helps submit this form... so it's possible that this is causing some difference versus normal links. Anyway, if that
hrefIShttps, then I'm not sure: it should be working. If it is NOT https (but you see https up in the address bar), then it's very possible that your Symfony app doesn't realize that it's in HTTPS, and so it's incorrectly generating HTTP URLs. If that's the case, it's probably a "trusted proxies" problem - https://symfony.com/doc/current/deployment/proxies.htmlLet me know if this helps.
Cheers!
Very nice, but unfortunately the Batch delete is still enabled for published Questions.
Hey Julien,
Ah, yes, good catch! You can do the same for "Action::BATCH_DELETE" I suppose, this should disable that as well.
Cheers!
Yup, I mention this in chapter 38 - https://symfonycasts.com/sc... - though I will admit that I had forgotten about it when doing this chapter :). But, we're already covered: in the previous chapter, we prevented approved questions from being deleted: https://symfonycasts.com/sc.... So the risk is that if you don't disable BATCH_DELETE (which I should have), that an admin user could get a 500 error if they select one that is approved.
Anyways, I'll add a note to this chapter so that people don't need to wait 4 more chapters to see my mention of this :).
Cheers!
Hello ! Why not just, in the configureActions method, declare an array with the actions ['edit', 'detail', 'delete'], and loop over it to update, disable, and hide?
(Unless the goal was really to show us how we could use a dto in a good way)
Hey Fabrice
I think there're a few ways to achieve it but the benefit of this particular way is that you isolate all the logic for hiding the delete action, it's a more error proof as well, you could create another CrudQuestion controller and forget to disable the delete action there, and, it's good for learning about subscribers and EasyAdmin DTOs :)
Cheers!
"Houston: no signs of life"
Start the conversation!