CommentTranslationHandler.php in Drupal 9
File
core/modules/comment/src/CommentTranslationHandler.php
View source
<?php
namespace Drupal\comment;
use Drupal\Core\Entity\EntityInterface;
use Drupal\content_translation\ContentTranslationHandler;
use Drupal\Core\Form\FormStateInterface;
class CommentTranslationHandler extends ContentTranslationHandler {
public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
parent::entityFormAlter($form, $form_state, $entity);
if (isset($form['content_translation'])) {
$form['content_translation']['status']['#access'] = FALSE;
$form['content_translation']['name']['#access'] = FALSE;
$form['content_translation']['created']['#access'] = FALSE;
}
}
protected function entityFormTitle(EntityInterface $entity) {
return t('Edit comment @subject', [
'@subject' => $entity
->label(),
]);
}
public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
if ($form_state
->hasValue('content_translation')) {
$translation =& $form_state
->getValue('content_translation');
$translation['status'] = $entity
->isPublished();
$translation['name'] = $entity
->getAuthorName();
}
parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
}
}