- π¨π¦Canada endless_wander
I used this functionality successfull to add headers for my use case of wanting X-Robot-Tag added to every PDF generated by the module.
Here is an example
added to module services.yml:
my_custom.events: class: Drupal\my_custom\EventSubscriber\MyEventSubscriber tags: - { name: event_subscriber }
Then in the modules/custom/my_custom/src/EventSubscriber/MyEventSubscriber.php:
namespace Drupal\my_custom\EventSubscriber; use Drupal\entity_print\Event\PrintEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\GenericEvent; /** * Add custom headers. */ class MyEventSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { $events[PrintEvents::CONFIGURATION_ALTER][] = ['onEntityPrintConfigurationAlter']; return $events; } /** * React to an event fired when retrieving a Print engine configuration. * * @param \Symfony\Component\EventDispatcher\GenericEvent $event * Generic event containing the print engine configuration. */ public function onEntityPrintConfigurationAlter(GenericEvent $event) { $configuration = $event->getArgument('configuration'); $configuration['headers']['X-Robot-Tag'] = 'noindex,nofollow,noarchive'; $event->setArgument('configuration', $configuration); } }
This was enough for me to have the headers appear on every PDF.
- πΊπ¦Ukraine Terry_Kolodiy
Changes from MR in combination with the event subscriber from #8 β¨ Possibility to alter http headers when we generate PDF Postponed: needs info work great for me.
Thanks! - π¨π¦Canada endless_wander
I believe there is a typo in my code from #8 -- should be "X-Robots-Tag" and not "X-Robot-Tag"