Hey,
We have a site translatable with i18n.
A problem we found is that the metatag data is saved correctly to the metatag table, but when you reedit the entity, the defaults are always shown.
This means when resaving, it saves the defaults.
I could pinpoint the problem to this snippet in metatags_metatags_form()
// Work out the language code to use, default to NONE.
$langcode = LANGUAGE_NONE;
if (isset($form['#entity_type']) && isset($form['#entity'])) {
$langcode = metatag_entity_get_language($form['#entity_type'], $form['#entity']);
}
On a node, $form['#entity_type'] is set to 'node',
$form['#entity'] is not set,
but $form['#node'] is set.
On a taxonomy_term, $form['#entity_type'] is set to 'taxonomy_term',
$form['#entity'] is not set,
but $form['#term'] is set.
Apparently the entity is available under the 'token type' info from enitity_get_info().
Code underneath fixes this.
// Work out the language code to use, default to NONE.
$langcode = LANGUAGE_NONE;
if (isset($form['#entity_type']) && $entity_info = entity_get_info($form['#entity_type'])) {
if(isset($form['#' . $entity_info['token type']])) {
$langcode = metatag_entity_get_language($form['#entity_type'], $form['#' . $entity_info['token type']]);
}
}
Patch coming up.
Cheers!
Tom
Comment | File | Size | Author |
---|---|---|---|
#20 | metatag-n2411477-20.patch | 1.14 KB | DamienMcKenna |
#10 | metatag-n2411477-10.patch | 856 bytes | DamienMcKenna |
Comments
Comment #1
DamienMcKennaOh dear.
Comment #2
betz CreditAttribution: betz commentedComment #3
betz CreditAttribution: betz commentedOops, wrong patch.
:)
Comment #4
DamienMcKennaComment #7
betz CreditAttribution: betz commentedComment #8
betz CreditAttribution: betz commentedComment #9
betz CreditAttribution: betz commentedComment #10
DamienMcKennaA minor simplification of the code.
Comment #11
DamienMcKennaThanks! Am hoping this resolves some of the oddities others have been seeing lately.
Comment #13
m.lebedev CreditAttribution: m.lebedev commentedI encountered a problem after the upgrade module.
The site has a multi-lingual.
LOCATION: /en/taxonomy/term/%tid/edit/en
EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids () (line 7766 of /www/includes/common.inc).
I did cancellation the current commit and the problem was gone.
Comment #14
betz CreditAttribution: betz commentedM.lebedev, can you give us some more info about your setup?
I can't seem to reproduce your error.
- Are you using the entity_translation or the i18n_taxonomy module for your vocabs?
- If you are using the i18n_taxonomy module, what is the tranlation setting of your vocab? 'Localize', 'translate', or 'fixed language'?
- What did you actual mean with 'I did cancellation the current commit'?
Comment #15
m.lebedev CreditAttribution: m.lebedev commentedDrupal (7.34)
Enabled modules related to taxonomy:
entity_translation (7.x-1.0-beta4)
i18n_field_group
i18n_field
i18n (7.x-1.12)
i18n_menu
i18n_panels
path_breadcrumbs_i18n
i18n_string
i18n_translation
i18n_variable
i18nviews
taxonomy_menu (7.x-2.0-alpha2)
I did reverse commit 4cea521e9a1624bc897620bdcde30d4d64f3ad27 to fix this error.
Comment #16
betz CreditAttribution: betz commentedJep, found the bug. It is specifically for entity translation.
Working on a patch that takes into account translations with both modules.
Comment #17
betz CreditAttribution: betz commentedOK. Could you test this patch against dev?
Comment #18
betz CreditAttribution: betz commentedAlso, about defaults:
Terms defaults has its own issue, see #2030427: Integration with i18n_taxonomy for per-language defaults
This is not the scope of this issue...
Comment #19
m.lebedev CreditAttribution: m.lebedev commentedThanks. The patch metatag-entitytokeni18n-2411477-17.patch solves the problem.
Comment #20
DamienMcKennaDoes this fix it?
Comment #21
m.lebedev CreditAttribution: m.lebedev commentedYes, #20 works.
Comment #22
DamienMcKennaThanks! Committed.
Comment #25
GaëlGIn taxonomy_form_term, there is
$form['#term'] = (array) $term;
But we need to pass an object to metatag_entity_get_language(). This fixed the bug:Comment #26
DamienMcKenna@GaelG: That bug was fixed in #2466629: EntityMalformedException thrown on taxonomy term edit page which was included in v1.5. Please update.
Also, please don't reopen old issues to report a different bug, and please only set an issue to "needs review" when there's a patch file to be reviewed.
Thank you.
Comment #27
GaëlGAllright, it's all my bad. I shouldn't post to d.o. when in a hurry...
Comment #28
DamienMcKenna@GaelG: No worries :) If you're in a hurry, opening a new issue is a better starting point than an existing fixed issue.