function translation_entity_entity_info_alter

Implements hook_entity_info_alter().

File

drupal/core/modules/translation_entity/translation_entity.module, line 55
Allows entities to be translated into different languages.

Code

function translation_entity_entity_info_alter(array &$entity_info) {
  $edit_form_info = array();

  // Provide defaults for translation info.
  foreach ($entity_info as $entity_type => &$info) {
    if (!isset($info['translation']['translation_entity'])) {
      $info['translation']['translation_entity'] = array();
    }

    // Every fieldable entity type must have a translation controller class, no
    // matter if it is enabled for translation or not. As a matter of fact we
    // might need it to correctly switch field translatability when a field is
    // shared accross different entities.
    $info += array(
      'translation_controller_class' => 'Drupal\\translation_entity\\EntityTranslationController',
    );

    // Check whether translation is enabled at least for one bundle. We cannot
    // use translation_entity_enabled() here since it would cause infinite
    // recursion, as it relies on entity info.
    $enabled = FALSE;
    $bundles = isset($info['bundles']) ? array_keys($info['bundles']) : array(
      $entity_type,
    );
    foreach ($bundles as $bundle) {
      if (translation_entity_get_config($entity_type, $bundle, 'enabled')) {
        $enabled = TRUE;
        break;
      }
    }
    if ($enabled) {

      // If no menu base path is provided we default to the usual
      // "entity_type/%entity_type" pattern.
      if (!isset($info['menu_base_path'])) {
        $path = "{$entity_type}/%{$entity_type}";
        $info['menu_base_path'] = $path;
      }
      $path = $info['menu_base_path'];
      $info += array(
        'menu_view_path' => $path,
        'menu_edit_path' => "{$path}/edit",
        'menu_path_wildcard' => "%{$entity_type}",
      );
      $entity_position = count(explode('/', $path)) - 1;
      $info['translation']['translation_entity'] += array(
        'access_callback' => 'translation_entity_translate_access',
        'access_arguments' => array(
          $entity_position,
        ),
      );
    }
  }
}