public function WebformCompositeForm::form in Webform Composite Tools 8
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ WebformCompositeForm.php, line 70
Class
- WebformCompositeForm
- Form handler for the Composite add and edit forms.
Namespace
Drupal\webform_composite\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$composite = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $composite
->label(),
'#description' => $this
->t('Name for the Composite.'),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $composite
->id(),
'#machine_name' => [
'exists' => [
$this,
'exists',
],
],
'#disabled' => !$composite
->isNew(),
];
$form['description'] = [
'#type' => 'webform_html_editor',
'#title' => $this
->t('Administrative description'),
'#default_value' => $composite
->getDescription(),
];
$form['elements'] = [
'#type' => 'webform_element_composite',
'#title' => $this
->t('Elements'),
'#title_display' => $this
->t('Invisible'),
'#label' => $this
->t('element'),
'#labels' => $this
->t('elements'),
'#empty_items' => 0,
'#header' => TRUE,
];
// Load existing elements.
$default_value = [];
$elements = $composite
->getElementsDecoded();
foreach ($elements as $key => $properties) {
$composite_element = WebformArrayHelper::removePrefix($properties);
$default_value[$key] = $composite_element;
}
$form['elements']["#default_value"] = $default_value;
$form['#attached']['library'][] = 'webform/webform.element.composite.admin';
// You will need additional form elements for your custom properties.
return $form;
}