You are here

function _entity_translation_taxonomy_autocomplete_translation_enabled in Entity Translation 7

Checks whether in-place translation is enabled for the autocomplete widget.

Parameters

array $element: The widget form element.

array $form_state: The form state array.

Return value

bool TRUE if in-place translation is enabled, FALSE otherwise.

2 calls to _entity_translation_taxonomy_autocomplete_translation_enabled()
entity_translation_field_widget_taxonomy_autocomplete_form_alter in ./entity_translation.taxonomy.inc
Implements hook_field_widget_WIDGET_TYPE_form_alter().
entity_translation_taxonomy_autocomplete_validate in ./entity_translation.taxonomy.inc
Form element validate handler for taxonomy term autocomplete element.

File

./entity_translation.taxonomy.inc, line 165
The taxonomy specific translation functions and hook implementations.

Code

function _entity_translation_taxonomy_autocomplete_translation_enabled($element, $form_state) {
  $field = field_info_field($element['#field_name']);
  if (field_is_translatable($element['#entity_type'], $field)) {
    return FALSE;
  }
  list($id, , $bundle) = entity_extract_ids($element['#entity_type'], $element['#entity']);
  if (!$id) {
    return FALSE;
  }
  $entity_type = 'taxonomy_term';
  $parent_handler = entity_translation_get_handler($element['#entity_type'], $element['#entity']);
  $active_langcode = $parent_handler
    ->getActiveLanguage();
  $translations = $parent_handler
    ->getTranslations();
  $entity_langcode = isset($translations->original) ? $translations->original : LANGUAGE_NONE;
  $instance = field_info_instance($element['#entity_type'], $field['field_name'], $bundle);

  // We need to make sure that we are not dealing with a translation form.
  // However checking the active language is not enough, because the user may
  // have changed the entity language.
  return (isset($form_state['entity_translation']['is_translation']) ? $form_state['entity_translation']['is_translation'] : $active_langcode != $entity_langcode) && !empty($instance['settings']['entity_translation_taxonomy_autocomplete_translate']) && (user_access('translate any entity') || user_access("translate {$entity_type} entities"));
}