knowledge-8.x-1.x-dev/src/KnowledgeTranslationHandler.php
src/KnowledgeTranslationHandler.php
<?php
namespace Drupal\knowledge;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\content_translation\ContentTranslationHandler;
/**
* Defines the translation handler for knowledge.
*/
class KnowledgeTranslationHandler extends ContentTranslationHandler {
/**
* {@inheritdoc}
*/
public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
parent::entityFormAlter($form, $form_state, $entity);
if (isset($form['content_translation'])) {
// We do not need to show these values on knowledge forms: they inherit
// the basic knowledge property values.
$form['content_translation']['status']['#access'] = FALSE;
$form['content_translation']['created']['#access'] = FALSE;
}
}
/**
* {@inheritdoc}
*/
protected function entityFormTitle(EntityInterface $entity) {
return $this->t('Edit knowledge @subject', ['@subject' => $entity->label()]);
}
/**
* {@inheritdoc}
*/
public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
if ($form_state->hasValue('content_translation')) {
$translation = &$form_state->getValue('content_translation');
/** @var \Drupal\knowledge\KnowledgeInterface $entity */
$translation['status'] = $entity->isPublished();
}
parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
}
}
