Problem/Motivation
After #1497230: Use Dependency Injection to handle object definitions drush has been broken when calling t() too early in the bootstrap phase.
Fatal error: Class 'Drupal\Core\DependencyInjection\ContainerBuilder' not found in ...xxxxxx/drupal/core/includes/bootstrap.inc on line 2354
After much discussion about if this should be fixed in core or in drush in IRC and the issue queue including:
#1589182: Fatal error: Class '...ContainerBuilder' not found when executing drush status on a not yet installed Drupal
#1541990: Improve check before calling t() (D8 drupal_container() patch broke drush)
#1540110: Drush calling t() before D8 dependency injection construct is available
...and finally #322549: t() should work regardless of the bootstrap phase has a more complex and convoluted history. I suspect this patch is related, and will possibly be mute after that has settled out. However, we don't need core to be broken in this way in the meanwhile.
Proposed resolution
This patch is based on Moshe's comment: http://drupal.org/node/1569456#comment-5981226 We simply wrap ContainerBuilder in a conditional and return the untranslated string if Drupal is not ready yet.
Patch follows...
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | drupal8.t-containerbuilder.3.patch | 877 bytes | sun |
| #1 | translate_or_dont-1590182-1.patch | 797 bytes | ZenDoodles |
Comments
Comment #1
ZenDoodles commentedComment #3
sunI'm fairly sure you need to specify the fully qualified class name:
Drupal\Core\DependencyInjection\ContainerBuilder
When $args is empty, you need to return $string directly.
Lastly, I'm not sure whether this is the correct solution attempt and whether it doesn't actually make things worse.
Comment #4
ZenDoodles commentedAfter the failures, I was just coming back to post a patch that assumes english if ContainerBuilder doesn't exist yet. Not sure which approach is better.
This part on the other hand --WAY better than mine!
Comment #5
sunI'm fairly sure this only fixes a symptom by hiding it, but does not fix the actual cause.
Furthermore, I first want to see a test, which demonstrates that this bug actually exists in Drupal core (and not only Drush).
The actual error message of the fatal error itself clearly hints at Drush not really/properly accounting for the new PSR-0 based classloader in D8 core. Therefore, I've re-opened the Drush issue:
#1541990: Improve check before calling t() (D8 drupal_container() patch broke drush)
Comment #6
sun#1541990: Improve check before calling t() (D8 drupal_container() patch broke drush) was fixed.
It's a quick stop-gap fix only, but Drush needs to figure out how to adapt its bootstrap to correctly initialize the PSR-0 classloader in D8+ before calling into any API functions or subsystems.
@moshe pointed out an alternative direction, in which Drush dt() wouldn't attempt to use Drupal's t() in the first place. That said, since that call to t() happens without/before a Drupal bootstrap, format_string() (since D7) would be a more appropriate function to call, since nothing is translated in the first place.
Comment #7
sun