protected function ModuleBuilderComponentFormBase::elementArray in Module Builder 7.2
Set form element properties specific to array component properties.
Parameters
&$element: The form element for the component property.
FormStateInterface $form_state: The form state.
$property_info: The info array for the component property.
$form_default_value: The default value for the form element.
Return value
string The handling type to be applied to this element's value on submit.
File
- includes/
module_builder.form.inc, line 305
Class
- ModuleBuilderComponentFormBase
- Backport of ComponentFormBase from 8.x-3.x version.
Code
protected function elementArray(&$element, FormStateInterface $form_state, $property_info, $form_default_value) {
if (isset($property_info['options'])) {
if (isset($property_info['options_extra'])) {
// Show an autocomplete textfield.
// TODO: use Select or Other module for this when it has a stable
// release.
$element['#type'] = 'textfield';
$element['#description'] = (isset($sub_element['#description']) ? $sub_element['#description'] . ' ' : '') . t("Enter multiple values separated with a comma.");
$element['#autocomplete_route_name'] = 'module_builder.autocomplete';
$element['#autocomplete_route_parameters'] = [
'property_address' => implode(':', $element['#mb_property_address']),
];
if ($form_default_value) {
$form_default_value = implode(', ', $form_default_value);
}
$handling = 'autocomplete';
}
else {
$element['#type'] = 'checkboxes';
$element['#options'] = $property_info['options'];
if (is_null($form_default_value)) {
$form_default_value = [];
}
else {
$form_default_value = array_combine($form_default_value, $form_default_value);
}
$handling = 'checkboxes';
}
}
else {
$element['#type'] = 'textarea';
$element['#description'] = (string) $element['#description'] . ' ' . t("Enter one item per line.");
$form_default_value = implode("\n", $form_default_value);
$handling = 'textarea';
}
$element['#default_value'] = $form_default_value;
return $handling;
}