TermTranslationHandler.php in Drupal 10
File
core/modules/taxonomy/src/TermTranslationHandler.php
View source
<?php
namespace Drupal\taxonomy;
use Drupal\Core\Entity\EntityInterface;
use Drupal\content_translation\ContentTranslationHandler;
use Drupal\Core\Form\FormStateInterface;
class TermTranslationHandler extends ContentTranslationHandler {
public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
parent::entityFormAlter($form, $form_state, $entity);
$form['content_translation']['status']['#access'] = !isset($form['content_translation']);
$form['actions']['submit']['#submit'][] = [
$this,
'entityFormSave',
];
}
public function entityFormSave(array $form, FormStateInterface $form_state) {
if ($this
->getSourceLangcode($form_state)) {
$entity = $form_state
->getFormObject()
->getEntity();
$form_state
->setRedirectUrl($entity
->toUrl('edit-form'));
}
}
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();
}
parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
}
}