when title of term has been replace with name_field
and on the content type the term reference is using autocomplete widget
the new entered name are inserted into the term name (not in name_field)
and do not appear when one views the node

one has to go and edit the term and insert the term name (this time in name_field) and translate the term

Comments

plach’s picture

Project: Entity Translation » Title

This is a title issue.

maciej lukianski’s picture

Title: Compatibility with autocomplete widget of term reference » Compatibility with term reference

There are more issues with term reference.

A different scenario of adding term via taxonomy ui.

When a new term with name_field is created the $term->title is empty. When this term is referenced from a node, the link does not appear on the display even though the term is referenced.

plach’s picture

Status: Active » Postponed (maintainer needs more info)

Please check with the latest dev of Core, Title and ET (Entity not required anymore).

Anonymous’s picture

I have another compatibility issue with therm reference.
All my content is set up to use English as the main language, then I have translations for all other languages on the site.

If you are viewing a site with a different language, and then edit the node form, which is English, the term names used in autocomplete/tagging term reference fields get the translated name. And when the form is saved, new terms are created using those translated term names.

Since I need this module for my site, and I need this to work properly, and not keep creating new terms if the node is edited when switched to a different language, I came up with a make-shift solution.
I added an element validation callback, similar to how the taxonomy autocomplete does already.
I check the term values to see if any are 'autocreate', then try to find that term name using the current language.

/**
 * Implements hook_field_widget_form_alter()
 * @param array $element
 * @param array $form_state
 * @param array $context
 */
function title_field_widget_form_alter(&$element, &$form_state, $context) {
  if ($context['field']['type'] == 'taxonomy_term_reference') {
    if ($context['instance']['widget']['type'] == 'taxonomy_autocomplete') {
      $element['#element_validate'][] = 'title_taxonomy_reference_field_validate';
    }
  }
}

/**
 * Custom taxonomy term validation
 * @param array $element
 * @param array $form_state
 */
function title_taxonomy_reference_field_validate($element, &$form_state) {
  global $language;
  
  //check if we need to check for translated term names
  if (!empty($form_state['input']['language']) && $language->language != $form_state['input']['language']) {
    // get the replacement field name
    $title_field = title_field_replacement_info('taxonomy_term', 'name');
    $name_field_name = $title_field['field']['field_name'];
  
    if (!empty($form_state['values'][$element['#field_name']][$element['#language']])) {
      foreach ($form_state['values'][$element['#field_name']][$element['#language']] as &$term) {
        // if it wasn't already matched, check against the name existsing in current language
        if ($term['tid'] == 'autocreate') {
          $tid = db_query("SELECT entity_id FROM {field_data_{$name_field_name}}
           WHERE entity_type = 'taxonomy_term' AND bundle = :vocab AND language = :lang AND {$name_field_name}_value LIKE :value", array(
            ':vocab' => $term['vocabulary_machine_name'],
            ':lang' => $language->language,
            ':value' => "%$term[name]%"
          ))->fetchField(0);

          if ($tid) {
            $term = (array)taxonomy_term_load($tid);
          }
        }
      }
    }
  }
}
plach’s picture

giorgosk’s picture

Status: Postponed (maintainer needs more info) » Fixed

yes OP incompatibilty has been solved but here is another term reference incompatibility which I created here #1920096: Title incompatibility with the entity reference widget

giorgosk’s picture

I would swear I have seen this working in the past
but now testing again it does not

when you create term with Name replaced with Title field the list of the taxonomy terms (of the particular vocabulary) does not display ANY name (admin/structure/taxonomy/VOCNAME) but when you edit the term
the NAME (title_field) has content in it

maybe this is the same problem as #1920096: Title incompatibility with the entity reference widget ?

should all those taxonomy incompatibilities be dealt in one issue ?

giorgosk’s picture

Status: Fixed » Active