function ContentTranslationEnableTranslationPerBundle::configElementProcess
Same name and namespace in other branches
- main core/modules/content_translation/src/ContentTranslationEnableTranslationPerBundle.php \Drupal\content_translation\ContentTranslationEnableTranslationPerBundle::configElementProcess()
Provides the language enable/disable form element.
Parameters
array $element: The initial form element.
\Drupal\Core\Form\FormStateInterface $formState: The form current state.
array $form: The form render array.
Return value
array The form element render array.
1 call to ContentTranslationEnableTranslationPerBundle::configElementProcess()
- ContentTranslationEnableTranslationPerBundle::getWidget in core/
modules/ content_translation/ src/ ContentTranslationEnableTranslationPerBundle.php - Returns the widget to be used per entity bundle.
File
-
core/
modules/ content_translation/ src/ ContentTranslationEnableTranslationPerBundle.php, line 72
Class
- ContentTranslationEnableTranslationPerBundle
- Provides a widget to enable content translation per entity bundle.
Namespace
Drupal\content_translationCode
public function configElementProcess(array $element, FormStateInterface $formState, array &$form) : array {
if (!empty($element['#content_translation_skip_alter']) || !$this->currentUser
->hasPermission('administer content translation')) {
return $element;
}
$key = $element['#name'];
$formState->set([
'content_translation',
'key',
], $key);
$context = $formState->get([
'language',
$key,
]);
$element['content_translation'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable translation'),
// For new bundle, we don't know the bundle name yet, default to no
// translatability.
'#default_value' => $context['bundle'] && $this->contentTranslationManager
->isEnabled($context['entity_type'], $context['bundle']),
'#element_validate' => [
self::class . ':configElementValidate',
],
];
$submitName = isset($form['actions']['save_continue']) ? 'save_continue' : 'submit';
// Only add the submit handler on the submit button if the #submit property
// is already available, otherwise this breaks the form submit function.
if (isset($form['actions'][$submitName]['#submit'])) {
$form['actions'][$submitName]['#submit'][] = self::class . ':configElementSubmit';
}
else {
$form['#submit'][] = self::class . ':configElementSubmit';
}
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.