function field_has_translation_handler

Checks if a module is registered as a translation handler for a given entity.

If no handler is passed, the function simply checks if there is any translation handler enabled for the given entity type.

Parameters

$entity_type: The type of the entity whose fields are to be translated.

$handler: (optional) The name of the handler to be checked. Defaults to NULL.

Return value

TRUE, if the given handler is allowed to manage field translations. If no handler is passed, TRUE means there is at least one registered translation handler.

Related topics

5 calls to field_has_translation_handler()
EntityFormController::submitEntityLanguage in drupal/core/lib/Drupal/Core/Entity/EntityFormController.php
Handle possible entity language changes.
field_is_translatable in drupal/core/modules/field/field.multilingual.inc
Checks whether a field has language support.
field_language in drupal/core/modules/field/field.multilingual.inc
Returns the display language code for the fields attached to the given entity.
hook_field_language_alter in drupal/core/modules/field/field.api.php
Perform alterations on field_language() values.
translation_entity_enabled in drupal/core/modules/translation_entity/translation_entity.module
Determines whether the given entity type is translatable.
1 string reference to 'field_has_translation_handler'
field_test_entity_info_translatable in drupal/core/modules/field/tests/modules/field_test/field_test.entity.inc
Helper function to enable entity translations.

File

drupal/core/modules/field/field.multilingual.inc, line 228
Functions implementing Field API multilingual support.

Code

function field_has_translation_handler($entity_type, $handler = NULL) {
  $entity_info = entity_get_info($entity_type);
  if (isset($handler)) {
    return !empty($entity_info['translation'][$handler]);
  }
  elseif (isset($entity_info['translation'])) {
    foreach ($entity_info['translation'] as $handler_info) {

      // The translation handler must use a non-empty data structure.
      if (!empty($handler_info)) {
        return TRUE;
      }
    }
  }
  return FALSE;
}