It should be good to have some clear standard for this question, raised first on this issue #1785086: Introduce a generic API for interface translation strings, but it would affect any other storage controller like the ones created in entity_get_controller() (entity.inc)
As a side issue, I'd like to clarify too what is the right way to define the class to be used for the storage controller when there is'nt hook_info() to declare it, like in that locale_storage() function in the linked issue.
Comment | File | Size | Author |
---|---|---|---|
#25 | how_to_register_storage-1806756-25.patch | 3.23 KB | hitesh-jain |
#22 | 1806756-22.patch | 3.29 KB | yogeshmpawar |
#17 | 1806756-17.patch | 4.41 KB | chishah92 |
#13 | 1806756-13.patch | 4.34 KB | rpayanm |
#11 | interdiff.txt | 7.81 KB | alansaviolobo |
Comments
Comment #1
Jose Reyero CreditAttribution: Jose Reyero commentedIt seems the answer is in Drupal\Core\CoreBundle.php
Thus we'll need to create a LocaleBundle class, and register the storage like this:
This seems to work and be a clean usage of DIC. More feedback welcomed though.
Note: if you couldn't find any documentation either: Classes in mymodule/lib/Drupal/mymodule/MymoduleBundle are automatically loaded by Drupal core from DrupalKernel::registerBundles(). Note the capital 'M' in 'Mymodule'
Comment #2
Jose Reyero CreditAttribution: Jose Reyero commentedThat approach above seems to work, but not for install/update, for which the storage seems not to be created, though locale_storage() is invoked causing a DIC exception. This may be related to #1807272: Mixed locale issues with upgrade scripts, unit tests, 'Table simpletest..locales_source doesn't exist', etc...
Comment #3
Jose Reyero CreditAttribution: Jose Reyero commentedThis is the working patch atm for locale storage controller. This is quite some special case, as noted in the locale_storage() function's comments so we need to handle the case of no locale storage present in DIC too.
Comment #4
tstoecklerI don't think the second argument is necessary. If I wanted locale.storage to use a non-default database, I would do the following:
That way local.storage doesn't need to know about database targets.
Comment #5
tstoecklerRestoring tag. The previous was a x-post.
Comment #6
tstoecklerOh, I just saw, that DatabaseStringStorage already takes an $option parameter, so #4 is bogus. (Or if at all, a follow-up.)
Comment #8
Jose Reyero CreditAttribution: Jose Reyero commentedWell, the patch fails but it actually fixes some issues. We get now real exceptions instead of "another exception thrown while handling one exception", which was happending before (because of #1808864: Exception handling is not 'locale safe' (thus not database safe))
This error is triggered by javascript file translation from the installer and would be in principle easy to fix, though this may not be the best solution:
I'll be exploring other options like initializing the storage on locale_language_init(). Though the indicated place to do it is LocaleBundle, this seems not to be installer/update safe, which is too bad :-(
Comment #9
Jose Reyero CreditAttribution: Jose Reyero commentedAfter some more research, it seems the locale storage is not a good candidate for a clean initialization because of the reasons outlined here, https://drupal.org/node/1807272#comment-6595134
Comment #10
jair CreditAttribution: jair commentedNeeds reroll
Comment #11
alansaviolobo CreditAttribution: alansaviolobo commentedComment #13
rpayanmrerolling...
Comment #16
chishah92 CreditAttribution: chishah92 at Blisstering Solutions commentedComment #17
chishah92 CreditAttribution: chishah92 at Blisstering Solutions commentedRerolled the patch.
Comment #19
chishah92 CreditAttribution: chishah92 at Blisstering Solutions commentedComment #21
hitesh-jain CreditAttribution: hitesh-jain at Acquia commentedComment #22
yogeshmpawarI have rerolled the patch to work with 8.2.x branch.
Comment #24
hitesh-jain CreditAttribution: hitesh-jain at Acquia commentedComment #25
hitesh-jain CreditAttribution: hitesh-jain at Acquia commentedPatch rerolled against 8.3.x branch.
Comment #27
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commented