protected function WebformTranslationConfigManager::buildConfigWebformFormImageSelectPropertyElement in Webform 6.x
Build config webform form image select property element.
Parameters
array $element: The Webform element.
array $translation_element: The Webform element's translated properties.
array $source_element: The Webform element's source properties.
array $parents: The Webform element's parents.
Return value
array A render array containing config webform form image select property element.
1 call to WebformTranslationConfigManager::buildConfigWebformFormImageSelectPropertyElement()
- WebformTranslationConfigManager::buildConfigWebformFormElements in src/
WebformTranslationConfigManager.php - Build config webform form elements.
File
- src/
WebformTranslationConfigManager.php, line 571
Class
- WebformTranslationConfigManager
- Defines a class to translate webform config.
Namespace
Drupal\webformCode
protected function buildConfigWebformFormImageSelectPropertyElement(array $element, array $translation_element, array $source_element, $property_parents) {
$property_key = end($property_parents);
$property_name = '#' . $property_key;
$webform_element = $this->elementManager
->getElementInstance($element);
$element_property = $this
->getWebformElementProperty($webform_element
->getPluginId(), $property_name);
$property_value = $translation_element[$property_name];
$property_title = isset($element_property['#title']) ? $element_property['#title'] : $property_name;
// Images.
$translation_images = $property_value;
$source_images = $source_element[$property_name];
// Header.
$header = [
'source' => [
'data' => $this
->t('Image text/src'),
'width' => '50%',
],
'translation' => [
'data' => $this
->t('Image text/src'),
'width' => '50%',
],
];
// Rows.
$rows = [];
foreach ($translation_images as $image_value => $image) {
$t_args = [
'@value' => $image_value,
'@text' => $source_images[$image_value]['text'],
'@src' => $source_images[$image_value]['src'],
];
$image_src = $source_images[$image_value]['src'];
try {
$image_url = Url::fromUri($source_images[$image_value]['src']);
} catch (\Exception $exception) {
$image_url = NULL;
}
$row = [
'source' => [
'text' => [
'#markup' => $this
->t('@text (@value)', $t_args),
'#suffix' => '<br/>',
],
'src' => $image_url ? [
'#type' => 'link',
'#url' => $image_url,
'#title' => $image_src,
] : [
'#markup' => $image_src,
],
],
'translation' => [
'text' => [
'#type' => 'textfield',
'#title' => $this
->t('Image text (@value)', $t_args),
'#title_display' => 'invisible',
'#default_value' => $image['text'],
'#parents' => array_merge($property_parents, [
$image_value,
'text',
]),
],
'src' => [
'#type' => 'textfield',
'#title' => $this
->t('Image src (@value)', $t_args),
'#title_display' => 'invisible',
'#default_value' => $image['src'],
'#parents' => array_merge($property_parents, [
$image_value,
'src',
]),
],
],
];
if (function_exists('imce_process_url_element')) {
imce_process_url_element($row['translation']['src'], 'link');
}
$rows[] = $row;
}
$element = [
'#type' => 'item',
'#title' => $property_title,
'options' => [
'#type' => 'table',
'#header' => $header,
] + $rows,
];
if (function_exists('imce_process_url_element')) {
$element['#attached']['library'][] = 'webform/imce.input';
}
return $element;
}