You are here

function content_translation_enable_widget in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_translation/content_translation.module \content_translation_enable_widget()

Returns a widget to enable content translation per entity bundle.

Backward compatibility layer to support entities not using the language configuration form element.

@todo Remove once all core entities have language configuration.

Parameters

string $entity_type: The type of the entity being configured for translation.

string $bundle: The bundle of the entity being configured for translation.

array $form: The configuration form array.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

1 call to content_translation_enable_widget()
AccountSettingsForm::buildForm in core/modules/user/src/AccountSettingsForm.php
Form constructor.

File

core/modules/content_translation/content_translation.module, line 561
Allows entities to be translated into different languages.

Code

function content_translation_enable_widget($entity_type, $bundle, array &$form, FormStateInterface $form_state) {
  $key = $form_state
    ->get([
    'content_translation',
    'key',
  ]);
  $context = $form_state
    ->get([
    'language',
    $key,
  ]) ?: [];
  $context += [
    'entity_type' => $entity_type,
    'bundle' => $bundle,
  ];
  $form_state
    ->set([
    'language',
    $key,
  ], $context);
  $element = content_translation_language_configuration_element_process([
    '#name' => $key,
  ], $form_state, $form);
  unset($element['content_translation']['#element_validate']);
  return $element;
}