3 namespace Drupal\comment;
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\content_translation\ContentTranslationHandler;
7 use Drupal\Core\Form\FormStateInterface;
10 * Defines the translation handler for comments.
12 class CommentTranslationHandler extends ContentTranslationHandler {
17 public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
18 parent::entityFormAlter($form, $form_state, $entity);
20 if (isset($form['content_translation'])) {
21 // We do not need to show these values on comment forms: they inherit the
22 // basic comment property values.
23 $form['content_translation']['status']['#access'] = FALSE;
24 $form['content_translation']['name']['#access'] = FALSE;
25 $form['content_translation']['created']['#access'] = FALSE;
32 protected function entityFormTitle(EntityInterface $entity) {
33 return t('Edit comment @subject', ['@subject' => $entity->label()]);
39 public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
40 if ($form_state->hasValue('content_translation')) {
41 $translation = &$form_state->getValue('content_translation');
42 /** @var \Drupal\comment\CommentInterface $entity */
43 $translation['status'] = $entity->isPublished();
44 $translation['name'] = $entity->getAuthorName();
46 parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);