public function WebformUiEntityElementsForm::buildForm in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_ui/src/WebformUiEntityElementsForm.php \Drupal\webform_ui\WebformUiEntityElementsForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides WebformEntityAjaxFormTrait::buildForm
File
- modules/
webform_ui/ src/ WebformUiEntityElementsForm.php, line 90
Class
- WebformUiEntityElementsForm
- Webform manage elements UI form.
Namespace
Drupal\webform_uiCode
public function buildForm(array $form, FormStateInterface $form_state) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $this
->getEntity();
$header = $this
->getTableHeader();
$elements = $this
->getOrderableElements();
// Get (weight) delta parent options.
$delta = count($elements);
$parent_options = $this
->getParentOptions($elements);
// Build table rows for elements.
$rows = [];
foreach ($elements as $element) {
$rows[$element['#webform_key']] = $this
->getElementRow($element, $delta, $parent_options);
}
$form['webform_ui_elements'] = [
'#type' => 'table',
'#header' => $header,
'#empty' => $this
->t('Please add elements to this webform.'),
'#attributes' => [
'class' => [
'webform-ui-elements-table',
],
],
'#tabledrag' => [
[
'action' => 'match',
'relationship' => 'parent',
'group' => 'row-parent-key',
'source' => 'row-key',
'hidden' => TRUE,
/* hides the WEIGHT & PARENT tree columns below */
'limit' => FALSE,
],
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'row-weight',
],
],
] + $rows;
if ($rows && !$webform
->hasActions()) {
$form['webform_ui_elements'] += [
'webform_actions_default' => $this
->getCustomizeActionsRow(),
];
}
// Must preload libraries required by (modal) dialogs.
WebformDialogHelper::attachLibraries($form);
$form['#attached']['library'][] = 'webform/webform.admin.tabledrag';
$form['#attached']['library'][] = 'webform_ui/webform_ui';
$form = parent::buildForm($form, $form_state);
return $this
->buildAjaxForm($form, $form_state);
}