Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Follow up from #1845034: Convert standard.inc to Drupal\Core\Language
Comment | File | Size | Author |
---|---|---|---|
#31 | 2004506-standard_country_list-31.patch | 24.72 KB | Cameron Tod |
#31 | interdiff_27-31.txt | 590 bytes | Cameron Tod |
#27 | 2004506-standard_country_list-27.patch | 24.63 KB | Cameron Tod |
#27 | interdiff_23-27.txt | 2.34 KB | Cameron Tod |
#23 | 2004506-standard_country_list-23.patch | 23.27 KB | Cameron Tod |
Comments
Comment #1
Cameron Tod CreditAttribution: Cameron Tod commentedComment #2
Cameron Tod CreditAttribution: Cameron Tod commentedMoved into utility class. Wasn't quite sure what to do with country_get_list(), so I left it in. It's only called in a couple of places, but I didn't want to replace those calls with \Drupal\Utility\Country::getStandardList(), as country_get_list() has a call to drupal_alter().
How do we now implement alter hook type functionality?
Comment #3
plachThis is already looking very good!
On one hand I think we could simply leave this as is, since it's already removing the offending includes in favor of an autoloaded class. If we want to go the full route, I guess we'll need to register
Country
as a DIC service (seecore.services.yml
), inject themodule_handler
service into it, and introduce a non-staticCountry::getList()
method that would leverage the MH service to alter the value returned byCountry::getStandardList()
, which should become non-static too.The end usage would look something like this:
Comment #4
Cameron Tod CreditAttribution: Cameron Tod commentedLike this? New ground for me :)
Comment #5
plachOne more thing: this should become a protected class variable. If we make Country a service we'll a singleton instance, hence it would be ok to have a non-static variable, which would be more flexible to deal with.
Comment #6
Cameron Tod CreditAttribution: Cameron Tod commentedMove $countries to \Drupal\Core\Utility\Country::countries.
Comment #7
Cameron Tod CreditAttribution: Cameron Tod commentedInterdiff for above.
Comment #8
plachSorry, #5 was a crosspost. Didn't see #4 yet, nice work :)
Some more fixes and then we should be ready to go:
Probably for consistency with other services we should rename this to
country_manager
andCountryManager
respectively.Isn't the DIC available, here?
Drupal::service('country_manager')
...This should implement a
CountryManagerInterface
. See the documentation of theDrupal
class for more details on dependecy injection.This should be non static so we can swap the actual implementation.
It would be better to inject the country manager when instantiating the
RegionalForm
object instead of directly retrieving it from the DIC, if there is a way to do it.I think it's ok to directly instantiate the
CountryManager
class here.Comment #9
Cameron Tod CreditAttribution: Cameron Tod commentedMoved \Drupal\Core\Utility\Country to Drupal\Core\Locale\CountryManager, and created a CountryManagerInterface.
Hopefully this is all ok. I think update-iso-3166.sh might be a bit ropey, but it *seems* to work.
Comment #10
plachThis should be
->getList()
.As I was saying above I don't think we should statically cache this, as we'd have no way to reset cache. A non-static class field should be fine since a service object is only instantiated once, normally.
This is not properly indented.
These are obviously unneeded :)
I think this should mention
\Drupal\Core\Locale\CountryManager::getList()
now.Comment #11
Cameron Tod CreditAttribution: Cameron Tod commentedThanks :)
Comment #12
plachAwesome! Just a couple of minor things and we are done:
I think that under certain PHP configurations this would cause an E_STRICT warning to be thrown:
static::getStandardList()
should be safer.One stale "use" left from the previous review :)
Ehm, this should be
\Drupal\Core\Locale\CountryManager::getList()
Comment #13
plach@cam8001:
Are you still working on this?
Comment #14
Cameron Tod CreditAttribution: Cameron Tod commentedYes! Planning to put aside some time tonight UTC. If I'm holding anything up feel free to push it through, but otherwise I'd like to finish it up.
Comment #15
plachCool, thanks!
Comment #16
Cameron Tod CreditAttribution: Cameron Tod commentedRebased and tweaked.
Comment #17
plachThere are still a couple of lingering wrong @see directives :(
Should be
\Drupal\Core\Locale\CountryManager::getStandardList()
.Should be
CountryManager::
.Comment #18
Cameron Tod CreditAttribution: Cameron Tod commentedDamn, sorry. Should be clean now.
Comment #19
plachThis is starting to get embarassing ;)
Core\Utility > \Drupal\Core\Locale
Utility > Locale
Comment #20
Cameron Tod CreditAttribution: Cameron Tod commentedMate, you're telling me!
I noticed there doesn't seem to be a consistent naming standard for @see directives or "Definition of" docblocks. Some are \Drupal\Namespace\Of\Class and others are Drupal\Namespace\Of\Class. I've gone with the first option, as I think it is less ambiguous. It also seems to be codified here: https://drupal.org/node/1354#see
Comment #21
plachAwesome!
Just a fresh reroll of #20. Looks good to me now :)
Comment #22
plach@cam8001:
If you wish to keep working on this stuff, there's #1845034: Convert standard.inc to Drupal\Core\Language that needs some more love :)
Comment #23
Cameron Tod CreditAttribution: Cameron Tod commentedReroll of #21.
Comment #24
plachRTBC again if the bot is happy
Comment #25
alexpottWe can inject the country manager by overriding create() and __construct from SystemConfigFormBase in RegionalForm.
Comment #26
plachAh, right, I had noted that somewhere above, forgot about it.
Comment #27
Cameron Tod CreditAttribution: Cameron Tod commentedInjected the country manager as suggested in #25.
Comment #29
plach#27: 2004506-standard_country_list-27.patch queued for re-testing.
Comment #31
Cameron Tod CreditAttribution: Cameron Tod commentedMissed some use statements.
Comment #32
plachRTBC if green :)
Comment #33
alexpottCommitted 07e3ccb and pushed to 8.x. Thanks!
Comment #34
plachAnd here it is :)
https://drupal.org/node/2019329