Chapters
46 Chapters
|
4:55:39
|
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!
43.
Free 3rd Party Controllers!
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 works perfectly with Stimulus 3!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "1.11.99.1", // 1.11.99.1
"doctrine/annotations": "^1.0", // 1.11.1
"doctrine/doctrine-bundle": "^2.2", // 2.2.3
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.0.2
"doctrine/orm": "^2.8", // 2.8.1
"phpdocumentor/reflection-docblock": "^5.2", // 5.2.2
"sensio/framework-extra-bundle": "^5.6", // v5.6.1
"symfony/asset": "5.2.*", // v5.2.3
"symfony/console": "5.2.*", // v5.2.3
"symfony/dotenv": "5.2.*", // v5.2.3
"symfony/flex": "^1.3.1", // v1.21.6
"symfony/form": "5.2.*", // v5.2.3
"symfony/framework-bundle": "5.2.*", // v5.2.3
"symfony/property-access": "5.2.*", // v5.2.3
"symfony/property-info": "5.2.*", // v5.2.3
"symfony/proxy-manager-bridge": "5.2.*", // v5.2.3
"symfony/security-bundle": "5.2.*", // v5.2.3
"symfony/serializer": "5.2.*", // v5.2.3
"symfony/twig-bundle": "5.2.*", // v5.2.3
"symfony/ux-chartjs": "^1.1", // v1.2.0
"symfony/validator": "5.2.*", // v5.2.3
"symfony/webpack-encore-bundle": "^1.9", // v1.11.1
"symfony/yaml": "5.2.*", // v5.2.3
"twig/extra-bundle": "^2.12|^3.0", // v3.2.1
"twig/intl-extra": "^3.2", // v3.2.1
"twig/twig": "^2.12|^3.0" // v3.2.1
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.0
"symfony/debug-bundle": "^5.2", // v5.2.3
"symfony/maker-bundle": "^1.27", // v1.30.0
"symfony/monolog-bundle": "^3.0", // v3.6.0
"symfony/stopwatch": "^5.2", // v5.2.3
"symfony/var-dumper": "^5.2", // v5.2.3
"symfony/web-profiler-bundle": "^5.2" // v5.2.3
}
}
What JavaScript libraries does this tutorial use?
// package.json
{
"devDependencies": {
"@babel/preset-react": "^7.0.0", // 7.12.13
"@popperjs/core": "^2.9.1", // 2.9.1
"@symfony/stimulus-bridge": "^2.0.0", // 2.1.0
"@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/Resources/assets", // 1.1.0
"@symfony/webpack-encore": "^1.0.0", // 1.0.4
"bootstrap": "^5.0.0-beta2", // 5.0.0-beta2
"core-js": "^3.0.0", // 3.8.3
"jquery": "^3.6.0", // 3.6.0
"react": "^17.0.1", // 17.0.1
"react-dom": "^17.0.1", // 17.0.1
"regenerator-runtime": "^0.13.2", // 0.13.7
"stimulus": "^2.0.0", // 2.0.0
"stimulus-autocomplete": "^2.0.1-phylor-6095f2a9", // 2.0.1-phylor-6095f2a9
"stimulus-use": "^0.24.0-1", // 0.24.0-1
"sweetalert2": "^10.13.0", // 10.14.0
"webpack-bundle-analyzer": "^4.4.0", // 4.4.0
"webpack-notifier": "^1.6.0" // 1.13.0
}
}
8 Comments
Hey @weaverryan do you have a solution you could share to somehow include controllers directory that is stored in a bundle? So except for including assets/controllers also to include vendor/myname/bundle/Resources/assets/controller? I cannot figure it out.
Hey Tomasz-I !
Hmm, that's an interesting question! You have a few options:
a) Simplest: Manually register them. With this solution, you're not loading an entire directory from a bundle, you just register the controllers you need one-by-one. I mention this first, because it's perfectly straightforward. In
bootstrap.js:b) Next simplest, and more of what you are after: importing an entire directory. The
startStimulusApp()function doesn't really have an "open door" to make this easy, so you just need to do it a bit more manually :).I haven't tested that (so let me know!) but that should to the trick. The
definitionsFromContextis normally called FOR you inside ofstartStimulusApp. So basically, this extra stuff at the bottom is replicating what happens inside of that function.c) the fancy option. Cause, we like fancy things, right!
This option involves treating your application like a "ux package". This is two steps:
1) Add your "bundle" to package.json as a "package" under the "require"
Then run
yarn install -fornpm install --force. You can actually use this part of the solution with solutions (a) and (b) if you want. It just means that, instead of referring to the paths with../vednor/myname/bundle..., you can reference as@vendor/your-bundle-name/controller... which is kind of cool :).Anyways, to register your controllers, you would update your
controllers.jsonfile to point at them:This would create a controller called "@vendor/your-bundle-name/controller1". To tell the system exactly where this file lives, in your
vendor/myname/bundle/Resources/assetsdirectory, you would have apackage.jsonfile that would include, among the normal stuff, this:The disadvantage of this is that... it's more work! And you can't load the entire directory automatically. The advantage would be if you are releasing a bundle that you would share with this world. By adding all of this config, when the user installs your bundle, their
package.jsonandcontrollers.jsonfiles would automatically update, and they would get the new controller by doing zero other setup.Phew! Probably a longer answer than you wanted, but I really liked the question :).
Cheers!
I'm in the same class as Jay - trying to stay current with Symfony just for "fun" since 2.3. In a project in Symfony 6.0.6 & yarn 3.2.0, I tried to add
stimulus-autocomplete@2. Compiling webpack failed with:
"./node_modules/stimulus-autocomplete/dist/stimulus-autocomplete.js" contains a reference to the file "stimulus". This file can not be found, please check it for typos or update it if the file got moved.
So I did "yarn remove stimulus-autocomplete", followed by "yarn add stimulus-autocomple@3". Webpack compiled nicely.
Hey geoB!
> I'm in the same class as Jay - trying to stay current with Symfony just for "fun" since 2.3
That's impressive!
> In a project in Symfony 6.0.6 & yarn 3.2.0, I tried to add
stimulus-autocomplete@2. Compiling webpack failed with:
Yup, if you're in a fresh Symfony project (which will be using Stimulus 3), then you want the latest stimulus-autocomplete version (version 3). We recommended installing version 2 in this tutorial only because the actual code I'm using (and the code in the course download) using Stimulus 2. To be it simply: Stimulus 2 ❤️ stimulus-autocomplete 2, and Stimulus 3 ❤️ stimulus-autocomplete 3.
Cheers!
I had to "yarn add stimulus-autocomplete@2" to get javascripts to build without error. Latest stimulus-autocomplete is 3, which has stimulus 3 as a dependency. But when upgraded stimulus then stimulus-bridge was not happy, and once again javascripts would not build.
As an aside, any ballpark timeframe on getting stimulus-bridge to work with stimulus 3, Ryan? OR, does stimulus 3 add anything worth being hurried about? Maybe stick with stimulus 2?
Hey @Jay Gee!
Ah, yay! stimulus-autocomplete has been updated for Stimulus 3 - that's good news :). So, some excellent questions here. Let me do my best to answer them:
> I had to "yarn add stimulus-autocomplete@2" to get javascripts to build without error.
Thanks - we'll update the script & video to show that :).
> As an aside, any ballpark timeframe on getting stimulus-bridge to work with stimulus 3, Ryan?
All the PR's to do this already exist - https://github.com/symfony/... and https://github.com/symfony/.... We were mostly waiting for the ecosystem to start releasing support - like stimulus-autocomplete, but also stimulus-use (which has not released support yet) https://github.com/stimulus...
> OR, does stimulus 3 add anything worth being hurried about? Maybe stick with stimulus 2?
Stimulus 3 is... no big deal! They released a new major version basically because thy changed the name of the library from "stimulus" to "@hotwired/stimulus". If it weren't for that, v3 would be v 2.1. They DID add a couple of nice features - https://world.hey.com/hotwi... - but it's all pretty minor stuff.
Anyways, once Symfony UX DOES give you Stimulus v3, we'll be adding some notes to this tutorial to mention some things... but Stimulus v2 is basically identical to Stimulus v3.
Cheers!
Awesome, thanks for the swift and thorough reply Ryan! I will add that Symfonycasts (I started when it was KNP U) is a Godsend for me. I'm so thankful for you, Leanna, and the entire Symfonycast crew! I've been following Symfony since 2.3. Completely self-taught and it's not my everyday job. I will also say that Stimulus integration has been the most exciting thing for me since learning Symfony!
Hey @Jay Gee!
Ah, you've been around since Symfony 2.3! It's been awhile - and things were pretty crazy way back then. Thanks for sticking with us - even more impressive if this isn't your everyday job! It should be! ;)
> I will also say that Stimulus integration has been the most exciting thing for me since learning Symfony!
I feel that same way - along with Turbo. It's completely changed the JavaScript paradigm for me, and allowed me to get that single-page-app experience with a "normal" app. We've been prepping the SymfonyCasts codebase for Turbo (mostly be refactoring legacy JavaScript into Stimulus, of course) - and I'm super excited.
Cheers!
"Houston: no signs of life"
Start the conversation!