- Issue created by @RichardDavies
- πΊπΈUnited States swirt Florida
Thank you for reporting this.
It looks like the same issue that is described here https://www.jeffgeerling.com/blog/2019/rendering-twig-templates-programm...
The twig engine is not loaded during VBO.
Seems like adding the twig service as avia dependency injection is the right way to go and might solve this edge case.
- πΊπΈUnited States RichardDavies Portland, Oregon
FYI I was able to create a temporary workaround by modifying my code as follows:
// Load the Twig theme engine so govdelivery_bulletins can use twig_render_template() when called from a VBO action. include_once \Drupal::root() . '/core/themes/engines/twig/twig.engine'; $twig = \Drupal::service('twig'); $twig_debug = $twig->isDebug(); if ($twig_debug) $twig->disableDebug(); \Drupal::service('govdelivery_bulletins.add_bulletin_to_queue')->addToQueueAndReset(); if ($twig_debug) $twig->enableDebug();
- πΊπΈUnited States swirt Florida
Interesting. I will push up a MR in a little while. But I will need you to tell me if solves the problem.
- πΊπΈUnited States swirt Florida
@richarddavies can you test the patch from this MR with your setup and let me know if it works?
https://git.drupalcode.org/project/govdelivery_bulletins/-/merge_request... - πΊπΈUnited States RichardDavies Portland, Oregon
I removed my workaround and applied the patch, but it's not working. Now I get this error during normal execution:
TypeError: Drupal\govdelivery_bulletins\Service\AddBulletinToQueue::__construct(): Argument #1 ($queue_factory) must be of type Drupal\Core\Queue\QueueFactoryInterface, Drupal\Core\Queue\QueueFactory given, called in /app/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 261 in Drupal\govdelivery_bulletins\Service\AddBulletinToQueue->__construct() (line 191 of modules/contrib/govdelivery_bulletins/src/Service/AddBulletinToQueue.php). Drupal\Component\DependencyInjection\Container->createService(Array, 'govdelivery_bulletins.add_bulletin_to_queue') (Line: 179) Drupal\Component\DependencyInjection\Container->get('govdelivery_bulletins.add_bulletin_to_queue') (Line: 197) Drupal::service('govdelivery_bulletins.add_bulletin_to_queue') (Line: 401) ...
And I get this error when using my VBO action:
ArgumentCountError: Too few arguments to function Drupal\govdelivery_bulletins\Service\AddBulletinToQueue::__construct(), 0 passed in /app/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 261 and exactly 2 expected in Drupal\govdelivery_bulletins\Service\AddBulletinToQueue->__construct() (line 191 of modules/contrib/govdelivery_bulletins/src/Service/AddBulletinToQueue.php). Drupal\Component\DependencyInjection\Container->createService(Array, 'govdelivery_bulletins.add_bulletin_to_queue') (Line: 179) Drupal\Component\DependencyInjection\Container->get('govdelivery_bulletins.add_bulletin_to_queue') (Line: 197) Drupal::service('govdelivery_bulletins.add_bulletin_to_queue') (Line: 401) ...
- πΊπΈUnited States swirt Florida
Thank you. I see the problem. working on a fix.
- πΊπΈUnited States swirt Florida
If you force refresh that patch I think that should solve those errors.
And again thank you for testing this out because I do not have a current site using this module.
- πΊπΈUnited States RichardDavies Portland, Oregon
Unfortunately, it's still not working. I get this error now during normal execution and VBO action:
Fatal error: Could not check compatibility between Drupal\govdelivery_bulletins\Service\AddBulletinToQueue::create(Drupal\govdelivery_bulletins\Service\ContainerInterface $container) and Drupal\Core\DependencyInjection\ContainerInjectionInterface::create(Symfony\Component\DependencyInjection\ContainerInterface $container), because class Drupal\govdelivery_bulletins\Service\ContainerInterface is not available in /app/web/modules/contrib/govdelivery_bulletins/src/Service/AddBulletinToQueue.php on line 200
- πΊπΈUnited States swirt Florida
Woah... never seen that one before. I'll dig into it this evening.
- πΊπΈUnited States swirt Florida
Ok this should do it.
One more time please. - πΊπΈUnited States RichardDavies Portland, Oregon
It worked from my VBO action, but I got this error during normal execution:
Warning: Undefined variable $queue in /app/web/modules/contrib/govdelivery_bulletins/src/Service/AddBulletinToQueue.php on line 407 The website encountered an unexpected error. Try again later. Error: Call to a member function deleteItem() on null in Drupal\govdelivery_bulletins\Service\AddBulletinToQueue->dedupeQueue() (line 407 of modules/contrib/govdelivery_bulletins/src/Service/AddBulletinToQueue.php). Drupal\govdelivery_bulletins\Service\AddBulletinToQueue->buildXml() (Line: 334) Drupal\govdelivery_bulletins\Service\AddBulletinToQueue->buildBulletinData() (Line: 285) Drupal\govdelivery_bulletins\Service\AddBulletinToQueue->addToQueue(NULL) (Line: 301) Drupal\govdelivery_bulletins\Service\AddBulletinToQueue->addToQueueAndReset() (Line: 417)
It looks like you forgot to replace
$queue
with$this->queue
on lines 407 and 427. - πΊπΈUnited States swirt Florida
Sorry. I missed the two instances of the $queue.
I just pushed a fix. - πΊπΈUnited States RichardDavies Portland, Oregon
Ok, we've got a winner. It now works without error when executed normally and when executed in my VBO action. Looks good!
- πΊπΈUnited States swirt Florida
Awesome. Thank you for playing "programming blind" with me. :)
I 'll get this merged and cut a release in a few minutes. - πΊπΈUnited States RichardDavies Portland, Oregon
Perfect, thank you so much for the quick response and fix!