You are here

function config_translation_entity_operation in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/config_translation/config_translation.module \config_translation_entity_operation()

Implements hook_entity_operation().

File

core/modules/config_translation/config_translation.module, line 156
Configuration Translation module.

Code

function config_translation_entity_operation(EntityInterface $entity) {
  $operations = [];
  $entity_type = $entity
    ->getEntityType();
  if ($entity_type
    ->entityClassImplements(ConfigEntityInterface::class) && $entity
    ->hasLinkTemplate('config-translation-overview') && \Drupal::currentUser()
    ->hasPermission('translate configuration')) {
    $link_template = 'config-translation-overview';
    if ($entity instanceof FieldConfigInterface) {
      $link_template = "config-translation-overview.{$entity->getTargetEntityTypeId()}";
    }
    $operations['translate'] = [
      'title' => t('Translate'),
      'weight' => 50,
      'url' => $entity
        ->toUrl($link_template),
    ];
  }
  return $operations;
}