function ContentTranslationEnableTranslationPerBundle::getWidget

Same name and namespace in other branches
  1. 11.x core/modules/content_translation/src/ContentTranslationEnableTranslationPerBundle.php \Drupal\content_translation\ContentTranslationEnableTranslationPerBundle::getWidget()

Returns the widget to be used per entity bundle.

Parameters

string $entityTypeId: 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 render array.

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

File

core/modules/content_translation/src/ContentTranslationEnableTranslationPerBundle.php, line 49

Class

ContentTranslationEnableTranslationPerBundle
Provides a widget to enable content translation per entity bundle.

Namespace

Drupal\content_translation

Code

public function getWidget(string $entityTypeId, string $bundle, array &$form, FormStateInterface $formState) : array {
  $key = $formState->get([
    'content_translation',
    'key',
  ]);
  $context = $formState->get([
    'language',
    $key,
  ]) ?: [];
  $context += [
    'entity_type' => $entityTypeId,
    'bundle' => $bundle,
  ];
  $formState->set([
    'language',
    $key,
  ], $context);
  $element = $this->configElementProcess([
    '#name' => $key,
  ], $formState, $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.