function ContentTranslationFormHooks::commentAdminOverviewFormAlter

Same name and namespace in other branches
  1. main core/modules/content_translation/src/Hook/ContentTranslationFormHooks.php \Drupal\content_translation\Hook\ContentTranslationFormHooks::commentAdminOverviewFormAlter()

Implements hook_form_FORM_ID_alter() for 'comment_admin_overview' form.

Attributes

#[Hook('form_comment_admin_overview_alter')]

File

core/modules/content_translation/src/Hook/ContentTranslationFormHooks.php, line 131

Class

ContentTranslationFormHooks
Form hook implementations for content_translation.

Namespace

Drupal\content_translation\Hook

Code

public function commentAdminOverviewFormAlter(array &$form, FormStateInterface $form_state) : void {
  $storage = $this->entityTypeManager
    ->getStorage('comment');
  $destination = $this->redirectDestination
    ->getAsArray();
  $comments = $storage->loadMultiple(array_keys($form['comments']['#options']));
  foreach ($comments as $cid => $comment) {
    if ($this->contentTranslationManager
      ->access($comment)
      ->isAllowed()) {
      $comment_uri_options = $comment->toUrl()
        ->getOptions() + [
        'query' => $destination,
      ];
      $form['comments']['#options'][$cid]['operations']['data']['#links']['translate'] = [
        'title' => $this->t('Translate'),
        'url' => $comment->toUrl('drupal:content-translation-overview', $comment_uri_options),
      ];
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.