function content_translation_field_sync_widget
Same name in other branches
- 8.9.x core/modules/content_translation/content_translation.admin.inc \content_translation_field_sync_widget()
- 10 core/modules/content_translation/content_translation.admin.inc \content_translation_field_sync_widget()
- 11.x core/modules/content_translation/content_translation.admin.inc \content_translation_field_sync_widget()
Returns a form element to configure field synchronization.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $field: A field definition object.
string $element_name: (optional) The element name, which is added to drupalSettings so that javascript can manipulate the form element.
Return value
array A form element to configure field synchronization.
2 calls to content_translation_field_sync_widget()
- content_translation_form_field_config_edit_form_alter in core/
modules/ content_translation/ content_translation.module - Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.
- _content_translation_form_language_content_settings_form_alter in core/
modules/ content_translation/ content_translation.admin.inc - (proxied) Implements hook_form_FORM_ID_alter().
File
-
core/
modules/ content_translation/ content_translation.admin.inc, line 31
Code
function content_translation_field_sync_widget(FieldDefinitionInterface $field, $element_name = 'third_party_settings[content_translation][translation_sync]') {
// No way to store field sync information on this field.
if (!$field instanceof ThirdPartySettingsInterface) {
return [];
}
$element = [];
$definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType());
$column_groups = $definition['column_groups'];
if (!empty($column_groups) && count($column_groups) > 1) {
$options = [];
$default = [];
$require_all_groups_for_translation = [];
foreach ($column_groups as $group => $info) {
$options[$group] = $info['label'];
$default[$group] = !empty($info['translatable']) ? $group : FALSE;
if (!empty($info['require_all_groups_for_translation'])) {
$require_all_groups_for_translation[] = $group;
}
}
$default = $field->getThirdPartySetting('content_translation', 'translation_sync', $default);
$element = [
'#type' => 'checkboxes',
'#title' => t('Translatable elements'),
'#options' => $options,
'#default_value' => $default,
];
if ($require_all_groups_for_translation) {
// The actual checkboxes are sometimes rendered separately and the parent
// element is ignored. Attach to the first option to ensure that this
// does not get lost.
$element[key($options)]['#attached']['drupalSettings']['contentTranslationDependentOptions'] = [
'dependent_selectors' => [
$element_name => $require_all_groups_for_translation,
],
];
$element[key($options)]['#attached']['library'][] = 'content_translation/drupal.content_translation.admin';
}
}
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.