protected function WebformContentCreatorManageFieldsForm::constructWebformField in Webform Content Creator 3.x
1 call to WebformContentCreatorManageFieldsForm::constructWebformField()
- WebformContentCreatorManageFieldsForm::constructTable in src/
Form/ WebformContentCreatorManageFieldsForm.php - Constructs table with mapping between webform and content type.
File
- src/
Form/ WebformContentCreatorManageFieldsForm.php, line 233
Class
- WebformContentCreatorManageFieldsForm
- Form handler for the Webform content creator manage fields form.
Namespace
Drupal\webform_content_creator\FormCode
protected function constructWebformField($field_id, array $webform_options, $attributes, $type, $component_field = NULL) {
$webform_field = [
'#type' => 'select',
'#title' => !empty($component_field) ? '(' . $component_field . ')' : NULL,
'#options' => $webform_options,
'#states' => [
'required' => [
':input[name="' . self::FORM_TABLE . '[' . $field_id . '][' . self::CONTENT_TYPE_FIELD . ']"]' => [
'checked' => TRUE,
],
],
],
];
if (array_key_exists($field_id, $attributes) && !$attributes[$field_id][self::CUSTOM_CHECK]) {
$form[self::FORM_TABLE][$field_id][self::WEBFORM_FIELD]['#default_value'] = $type . ',' . $attributes[$field_id][self::WEBFORM_FIELD];
if (!empty($component_field)) {
$webform_field['#states']['required'][':input[name="' . self::FORM_TABLE . '[' . $field_id . '][' . self::CUSTOM_CHECK . '][' . $component_field . ']"]'] = [
'checked' => FALSE,
];
if (array_key_exists($field_id, $attributes) && (!isset($attributes[$field_id][self::CUSTOM_CHECK][$component_field]) || !$attributes[$field_id][self::CUSTOM_CHECK][$component_field])) {
$webform_field['#default_value'] = $type . ',' . $attributes[$field_id][$component_field][self::WEBFORM_FIELD];
}
}
else {
$webform_field['#states']['required'][':input[name="' . self::FORM_TABLE . '[' . $field_id . '][' . self::CUSTOM_CHECK . ']"]'] = [
'checked' => FALSE,
];
if (array_key_exists($field_id, $attributes) && isset($attributes[$field_id][self::CUSTOM_CHECK]) && !$attributes[$field_id][self::CUSTOM_CHECK]) {
$webform_field['#default_value'] = $type . ',' . $attributes[$field_id][self::WEBFORM_FIELD];
}
}
// Textarea with custom text (including tokens)
$form[self::FORM_TABLE][$field_id][self::CUSTOM_VALUE] = [
'#type' => 'textarea',
'#default_value' => array_key_exists($field_id, $attributes) ? $attributes[$field_id][self::CUSTOM_VALUE] : '',
];
}
return $webform_field;
}