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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna’s picture

betz’s picture

FileSize
800 bytes
betz’s picture

Oops, wrong patch.
:)

DamienMcKenna’s picture

Status: Active » Needs review

The last submitted patch, 2: i18n_string-2227523-20.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 3: metatag-entitytokeni18n-2411477-1.patch, failed testing.

betz’s picture

FileSize
780 bytes
betz’s picture

betz’s picture

Status: Needs work » Needs review
DamienMcKenna’s picture

FileSize
856 bytes

A minor simplification of the code.

DamienMcKenna’s picture

Status: Needs review » Fixed

Thanks! Am hoping this resolves some of the oddities others have been seeing lately.

  • DamienMcKenna committed 4cea521 on 7.x-1.x authored by betz
    Issue #2411477 by betz, DamienMcKenna: $form[#entity] doesn't work for...
m.lebedev’s picture

Status: Fixed » Needs work

I 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.

betz’s picture

Status: Needs work » Postponed (maintainer needs more info)

M.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'?

m.lebedev’s picture

Drupal (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.

betz’s picture

Status: Postponed (maintainer needs more info) » Needs work

Jep, found the bug. It is specifically for entity translation.
Working on a patch that takes into account translations with both modules.

betz’s picture

Status: Needs work » Needs review
FileSize
1.16 KB

OK. Could you test this patch against dev?

betz’s picture

Also, about defaults:

  • the defaults for entity_translation are working fine.
  • The defaults for i18n (sub)modules depend on the entity_type:
    • Nodes are working fine
    • Terms are not.
    • Didn't test further

Terms defaults has its own issue, see #2030427: Integration with i18n_taxonomy for per-language defaults
This is not the scope of this issue...

m.lebedev’s picture

Thanks. The patch metatag-entitytokeni18n-2411477-17.patch solves the problem.

DamienMcKenna’s picture

FileSize
1.14 KB

Does this fix it?

m.lebedev’s picture

Yes, #20 works.

DamienMcKenna’s picture

Status: Needs review » Fixed

Thanks! Committed.

  • DamienMcKenna committed 4bd9160 on 7.x-1.x
    Issue #2411477 by DamienMcKenna, betz: Follow-up to last change.
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

GaëlG’s picture

Status: Closed (fixed) » Needs review

In 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:

if (!empty($form[$entity_key])) {
  $entity = (object) $form[$entity_key];
  $langcode = metatag_entity_get_language($form['#entity_type'], $entity);
}
DamienMcKenna’s picture

Status: Needs review » Closed (fixed)

@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.

GaëlG’s picture

Allright, it's all my bad. I shouldn't post to d.o. when in a hurry...

DamienMcKenna’s picture

@GaelG: No worries :) If you're in a hurry, opening a new issue is a better starting point than an existing fixed issue.