public function NodeTranslationHandler::entityFormAlter in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/src/NodeTranslationHandler.php \Drupal\node\NodeTranslationHandler::entityFormAlter()
- 9 core/modules/node/src/NodeTranslationHandler.php \Drupal\node\NodeTranslationHandler::entityFormAlter()
File
- core/modules/node/src/NodeTranslationHandler.php, line 17
Class
- NodeTranslationHandler
- Defines the translation handler for nodes.
Namespace
Drupal\node
Code
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;
}
$form_object = $form_state
->getFormObject();
$form_langcode = $form_object
->getFormLangcode($form_state);
$translations = $entity
->getTranslationLanguages();
$status_translatable = NULL;
if (!$entity
->isNew() && (!isset($translations[$form_langcode]) || count($translations) > 1)) {
foreach ($entity
->getFieldDefinitions() as $property_name => $definition) {
if ($property_name == 'status') {
$status_translatable = $definition
->isTranslatable();
}
}
if (isset($status_translatable)) {
if (isset($form['actions']['submit'])) {
$form['actions']['submit']['#value'] .= ' ' . ($status_translatable ? t('(this translation)') : t('(all translations)'));
}
}
}
}