You are here

function entity_translation_permission in Entity Translation 7

Implements hook_permission().

File

./entity_translation.module, line 784

Code

function entity_translation_permission() {
  $permission = array(
    'administer entity translation' => array(
      'title' => t('Administer entity translation'),
      'description' => t('Select which entities can be translated.'),
    ),
    'toggle field translatability' => array(
      'title' => t('Toggle field translatability'),
      'description' => t('Toggle translatability of fields performing a bulk update.'),
    ),
    'translate any entity' => array(
      'title' => t('Translate any entity'),
      'description' => t('Translate field content for any fieldable entity.'),
    ),
  );
  $workflow = entity_translation_workflow_enabled();
  if ($workflow) {
    $permission += array(
      'edit translation shared fields' => array(
        'title' => t('Edit shared values'),
        'description' => t('Edit values shared between translations on the entity form.'),
      ),
      'edit original values' => array(
        'title' => t('Edit original values'),
        'description' => t('Access any entity form in the original language.'),
      ),
    );
  }
  foreach (entity_get_info() as $entity_type => $info) {
    if ($info['fieldable'] && entity_translation_enabled($entity_type)) {
      $label = !empty($info['label']) ? t($info['label']) : $entity_type;
      $permission["translate {$entity_type} entities"] = array(
        'title' => t('Translate entities of type @type', array(
          '@type' => $label,
        )),
        'description' => t('Translate field content for entities of type @type.', array(
          '@type' => $label,
        )),
      );
      if ($workflow) {

        // Avoid access control for original values on the current entity.
        if (empty($info['translation']['entity_translation']['skip original values access'])) {
          $permission["edit {$entity_type} original values"] = array(
            'title' => t('Edit original values on entities of type @type', array(
              '@type' => $label,
            )),
            'description' => t('Access the entity form in the original language for entities of type @type.', array(
              '@type' => $label,
            )),
          );
        }

        // Avoid access control for shared fields on the current entity.
        if (empty($info['translation']['entity_translation']['skip shared fields access'])) {
          $permission["edit {$entity_type} translation shared fields"] = array(
            'title' => t('Edit @type shared values.', array(
              '@type' => $label,
            )),
            'description' => t('Edit values shared between translations on @type forms.', array(
              '@type' => $label,
            )),
          );
        }
      }
    }
  }
  return $permission;
}