Roomify / bat_drupal

Booking and Availability Management Tools for Drupal 7 and Drupal 8
33 stars 7 forks source link

Base path is too long to get BAT used with entity_translation module #62

Open borisbsu opened 4 years ago

borisbsu commented 4 years ago

Here is the base path for bat_type entity: admin/bat/config/types/manage/%bat_type

https://github.com/Roomify/bat_drupal/blob/67d355bb152a96138d9a25504a4aae5deacd0fb5/modules/bat_unit/bat_unit.module#L194

When entity translations are done using entity_translation module, then entity_translation programatically adds menu routes of such pattern: <base_path>/edit/add/%/%

in case of bat_type entity the full path will have 10 components: admin/bat/config/types/manage/%bat_type/edit/add/%/%

but Drupal 7 supports only maximum 9 parts in menu path:

image

so as I result we will get 404 Not Found errors for translate pages of bat_type entity:

image

borisbsu commented 4 years ago

The workaround is to:

  1. Override base path:
/**
 * Implements hook_entity_info_alter().
 */
function mymodule_entity_info_alter(&$entity_info) {
  $entity_info['bat_type']['translation']['entity_translation']['base path'] = 'type/%bat_type';
}
  1. Add corresponding menu routers for type/%bat_type and type/%bat_type/edit:
/**
 * Implements hook_menu().
 */
function mymodule_menu() {
  $items['type/%bat_type/edit'] = [
    'title callback' => 'bat_type_title_callback',
    'title arguments' => [1, 'edit'],
    'page callback' => 'bat_type_form_wrapper',
    'page arguments' => [1],
    'access callback' => 'bat_type_access',
    'access arguments' => ['update', 1],
    'weight' => 0,
    'type' => MENU_LOCAL_TASK,
    'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
    'file' => 'bat_type.admin.inc',
    'file path' => drupal_get_path('module', 'bat_unit'),
  ];
  ...
}