drupalextension icon indicating copy to clipboard operation
drupalextension copied to clipboard

Always bootstrap the API driver

Open jonathanjfshaw opened this issue 6 years ago • 2 comments

I was writing a subcontext, and got containerNotInitializedException when I wanted to call \Drupal::logger().

Because I know the extension well, it wasn't that hard for me to to track the jungle and figure out that I need to call $this->getDriver() to bootstrap Drupal. But for an innocent developer just wanting to write their own context, that's not easy to discern.

Can we bootstrap Drupal always if a feature is tagged @api?

jonathanjfshaw avatar Jul 19 '18 15:07 jonathanjfshaw

Lightning use this in their subcontexts and add it to every step function that needs it:

/**
  * Ensures the Drupal driver is bootstrapped.
  *
  * @throws \RuntimeException
  *   If the Drupal driver is not bootstrapped.
  */
 protected function ensureBootstrap() {
   if ($this->getDriver()->isBootstrapped() == FALSE) {
     throw new \RuntimeException('Drupal is not bootstrapped.');
   }
 }

jonathanjfshaw avatar Jul 19 '18 15:07 jonathanjfshaw

Note that #487 is related to early bootstrapping. I've opened #518 for discussion.

jhedstrom avatar Nov 06 '18 19:11 jhedstrom