Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/comment/src/CommentTranslationHandler.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\comment; | |
4 | |
5 use Drupal\Core\Entity\EntityInterface; | |
6 use Drupal\content_translation\ContentTranslationHandler; | |
7 use Drupal\Core\Form\FormStateInterface; | |
8 | |
9 /** | |
10 * Defines the translation handler for comments. | |
11 */ | |
12 class CommentTranslationHandler extends ContentTranslationHandler { | |
13 | |
14 /** | |
15 * {@inheritdoc} | |
16 */ | |
17 public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) { | |
18 parent::entityFormAlter($form, $form_state, $entity); | |
19 | |
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; | |
26 } | |
27 } | |
28 | |
29 /** | |
30 * {@inheritdoc} | |
31 */ | |
32 protected function entityFormTitle(EntityInterface $entity) { | |
33 return t('Edit comment @subject', ['@subject' => $entity->label()]); | |
34 } | |
35 | |
36 /** | |
37 * {@inheritdoc} | |
38 */ | |
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(); | |
45 } | |
46 parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state); | |
47 } | |
48 | |
49 } |