annotate core/modules/comment/src/CommentTranslationHandler.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\comment;
Chris@0 4
Chris@0 5 use Drupal\Core\Entity\EntityInterface;
Chris@0 6 use Drupal\content_translation\ContentTranslationHandler;
Chris@0 7 use Drupal\Core\Form\FormStateInterface;
Chris@0 8
Chris@0 9 /**
Chris@0 10 * Defines the translation handler for comments.
Chris@0 11 */
Chris@0 12 class CommentTranslationHandler extends ContentTranslationHandler {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * {@inheritdoc}
Chris@0 16 */
Chris@0 17 public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
Chris@0 18 parent::entityFormAlter($form, $form_state, $entity);
Chris@0 19
Chris@0 20 if (isset($form['content_translation'])) {
Chris@0 21 // We do not need to show these values on comment forms: they inherit the
Chris@0 22 // basic comment property values.
Chris@0 23 $form['content_translation']['status']['#access'] = FALSE;
Chris@0 24 $form['content_translation']['name']['#access'] = FALSE;
Chris@0 25 $form['content_translation']['created']['#access'] = FALSE;
Chris@0 26 }
Chris@0 27 }
Chris@0 28
Chris@0 29 /**
Chris@0 30 * {@inheritdoc}
Chris@0 31 */
Chris@0 32 protected function entityFormTitle(EntityInterface $entity) {
Chris@0 33 return t('Edit comment @subject', ['@subject' => $entity->label()]);
Chris@0 34 }
Chris@0 35
Chris@0 36 /**
Chris@0 37 * {@inheritdoc}
Chris@0 38 */
Chris@0 39 public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
Chris@0 40 if ($form_state->hasValue('content_translation')) {
Chris@0 41 $translation = &$form_state->getValue('content_translation');
Chris@0 42 /** @var \Drupal\comment\CommentInterface $entity */
Chris@0 43 $translation['status'] = $entity->isPublished();
Chris@0 44 $translation['name'] = $entity->getAuthorName();
Chris@0 45 }
Chris@0 46 parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
Chris@0 47 }
Chris@0 48
Chris@0 49 }