function translation_entity_entity_info_alter

Implements hook_entity_info_alter().

File

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

Code

function translation_entity_entity_info_alter(array &$entity_info) {

  // Provide defaults for translation info.
  foreach ($entity_info as $entity_type => &$info) {
    if (empty($info['translatable'])) {
      continue;
    }
    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['controllers'] += array(
      'translation' => 'Drupal\\translation_entity\\EntityTranslationController',
    );

    // 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,
      ),
    );
  }
}