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.
Hi,
while writing integration for tmgmt i found a odd behaviour in i18n_object(). The $key can be NULL after i18n_object_key().
Here is a drush snippet to show the issue.
drush php-eval '$types = array("article", "page"); foreach($types as $type) { $o = i18n_object("node_type", $type); print_r($o); }'
Comment | File | Size | Author |
---|---|---|---|
#10 | i18n_object_clean-1445344-10.patch | 4.97 KB | webflo |
#9 | i18n_object_clean.patch | 8.85 KB | Jose Reyero |
#6 | 1445344-fix-with-node-test.patch | 3.84 KB | webflo |
#4 | 1445344-broken-node-test.patch | 750 bytes | webflo |
#4 | 1445344-fix-with-node-test.patch | 3.84 KB | webflo |
Comments
Comment #1
webflo CreditAttribution: webflo commentedA test to expose the issue. This should break.
Comment #3
webflo CreditAttribution: webflo commentedComment #4
webflo CreditAttribution: webflo commented1445344-broken-node-test.patch should fail.
1445344-fix-with-node-test.patch should pass.
Comment #6
webflo CreditAttribution: webflo commentedits i18n_object_by_name().
Comment #7
Jose Reyero CreditAttribution: Jose Reyero commentedI am not that sure about this. Maybe the problem is allowing a key instead of an object in i18n_object().
What about keeping i18n_object() as the object wrapper which always takes an object parameter and adding some other i18n_object_by_key() function ? (or i18n_object_build_key())
Comment #8
miro_dietikerObject id or key?
Comment #9
Jose Reyero CreditAttribution: Jose Reyero commentedThis patch cleans up the i18n_object() API a little bit. I think part of the problem is using either object or object key as a parameter.
It also changes the default constructor for i18n_string_object(), not sure about this though.
Comment #10
webflo CreditAttribution: webflo commentedThis looks good. I committed the whitespace for easier review and re-roll.
Hmm i think this should be $this->load_object($key). Right?
New patch is attached.
Comment #11
Jose Reyero CreditAttribution: Jose Reyero commentedGreat, committed @webflo's version of the patch.
Also, tried the code at the top and it seems to work now.
I don't think we need anything else here, do we?
(Though I'm afraid tmgmt will need to keep depending on i18n-dev for now)