function content_translation_enable_widget

Same name and namespace in other branches
  1. 8.9.x core/modules/content_translation/content_translation.module \content_translation_enable_widget()
  2. 10 core/modules/content_translation/content_translation.module \content_translation_enable_widget()
  3. 11.x 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

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.