Problem/Motivation
I am using the webform_multiple
element in a custom WebformElement that is a composite element. When I go to the translation page in to translate the form, only the element title is visible to translate. I've stepped through all the code which led me to the Drupal\webform\WebformTranslationConfigManager::buildConfigWebformFormDefaultPropertyElement()
method that handles rendering the elements correctly on the add config translation form.
Here is an example of my custom element:
class CaseWizardOptions extends WebformElementBase {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state): array {
$form = parent::form($form, $form_state);
$form['solutions'] = [
'#type' => 'fieldset',
'#title' => $this->t('Solutions'),
'#open' => TRUE,
];
$form['solutions']['solutions'] = [
'#type' => 'webform_multiple',
'#empty_items' => 0,
'#element' => [
'action' => [
'#type' => 'select',
'#title' => $this->t('Action'),
'#options' => [
'recommendation' => $this->t('Show recommendation in modal'),
'open_case' => $this->t('Open case'),
'link_account' => $this->t('Link account'),
'open_new_page' => $this->t('Open new page'),
],
],
'title' => [
'#type' => 'textfield',
'#title' => $this->t('Title'),
],
'description' => [
'#type' => 'text_format',
'#title' => $this->t('Description'),
'#allowed_formats' => ['full_html'],
],
'recommendation_label' => [
'#type' => 'textfield',
'#title' => $this->t('Recommendation label'),
'#description' => $this->t('Use for recommendation modal action.'),
],
'recommendation' => [
'#type' => 'text_format',
'#title' => $this->t('Recommendation'),
'#description' => $this->t('Use for recommendation modal action.'),
'#allowed_formats' => ['full_html'],
],
'recommendations_url' => [
'#type' => 'url',
'#title' => $this->t('Recommendations url'),
'#description' => $this->t('Use for recommendation modal action.'),
],
'new_page_url' => [
'#type' => 'url',
'#title' => $this->t('New page url'),
'#description' => $this->t('Use for open new page action.'),
],
],
'#weight' => 100,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function getOffCanvasWidth(): string {
return WebformDialogHelper::DIALOG_WIDE;
}
/**
* {@inheritdoc}
*/
public function prepare(array &$element, ?WebformSubmissionInterface $webform_submission = NULL): void {
parent::prepare($element, $webform_submission);
foreach ($element['#solutions'] as $solution) {
$element['#options'][] = $solution;
}
$element['#attached']['library'][] = 'core/drupal.dialog.ajax';
}
/**
* {@inheritdoc}
*/
protected function defineDefaultProperties(): array {
$properties = parent::defineDefaultProperties();
$properties['solutions'] = [];
// Conditional logic.
$properties['states'] = [];
$properties['states_clear'] = TRUE;
// Wrapper.
$properties['wrapper_type'] = 'fieldset';
return $properties;
}
}
Steps to reproduce
Implement a custom webform element plugin with the example code I've provided above. Attempt to translate the webform and this element will only allow you to translate the element title.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes