I want to use https://github.com/KnpLabs/KnpSnappyBundle in a Drupal 8 project. How do I correctly use it?
Drupal 8 isn't using Symfony bundles, only some Symfony components. Therefore you should use https://github.com/KnpLabs/snappy instead of bundle you've mentioned. You should install it using
composer and then use available classes in your Drupal code. If you want to create PDF-generation service, you should follow official Drupal documentation.
I can't speak to configuring it as outlined in their documentation, but the typical way of using external packages is to install them with Composer, then one of these scenarios:
- Define a custom service in your module that injects that bundle as an argument
- In some cases, you could use
new ClassName(...)if thats how that package works
- Inject it from the container in your own classes create/construct method
Here is a more advanced method I wrote about some time ago about taking an external package and configuring it BEFORE it is injected to your class/service:
This might be more in line with what you need to do, since you do not have the Symfony config.yml/app.yml their documentation alludes to for Symfony apps, and you have a need to configure the service as it is injected. This also works for packages that have config methods but are framework independent, like Solarium is.
As Milos also mentioned, this seems like the package you are looking for: https://github.com/KnpLabs/snappy