1

I want to use https://github.com/KnpLabs/KnpSnappyBundle in a Drupal 8 project. How do I correctly use it?

3

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.

  • Thank you Miloš, @kevin ! – Alex Nov 18 at 7:13
  • You're welcome! – Miloš Kroulík Nov 18 at 8:20
1

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:

  1. Define a custom service in your module that injects that bundle as an argument
  2. In some cases, you could use new ClassName(...) if thats how that package works
  3. 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:

https://kevinquillen.com/dependency-inject-php-classes-drupal

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.