You are here

function entity_translation_edit_access in Entity Translation 7

Access callback.

1 string reference to 'entity_translation_edit_access'
entity_translation_menu_alter in ./entity_translation.module
Implements hook_menu_alter().

File

./entity_translation.module, line 573

Code

function entity_translation_edit_access() {
  $args = func_get_args();
  $entity_type = array_shift($args);
  $entity = array_shift($args);
  $langcode = array_shift($args);
  $edit_form_item = array_shift($args);
  $access_callback = isset($edit_form_item['access callback']) ? $edit_form_item['access callback'] : 'user_access';
  $handler = entity_translation_get_handler($entity_type, $entity);

  // First, check a handler has been loaded. This could be empty if a
  // non-existent entity edit path has been requested, for example. Delegate
  // directly to the edit form item access callback in this case.
  if (empty($handler)) {
    return _entity_translation_callback($access_callback, $args, $edit_form_item);
  }
  $translations = $handler
    ->getTranslations();
  $langcode = entity_translation_get_existing_language($entity_type, $entity, $langcode);

  // The user must be explicitly allowed to access the original values if
  // workflow permissions are enabled.
  if (!$handler
    ->getTranslationAccess($langcode)) {
    return FALSE;
  }

  // If the translation exists or no translation was specified, we can show the
  // corresponding local task. If translations have not been initialized yet, we
  // need to grant access to the user.
  if (empty($translations->data) || isset($translations->data[$langcode])) {

    // Check that the requested language is actually accessible. If the entity
    // is language neutral we need to let editors access it.
    $enabled_languages = entity_translation_languages($entity_type, $entity);
    if (isset($enabled_languages[$langcode]) || $langcode == LANGUAGE_NONE) {
      return _entity_translation_callback($access_callback, $args, $edit_form_item);
    }
  }
  return FALSE;
}