You are here

public function WebformUiElementTypeFormBase::buildForm in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_ui/src/Form/WebformUiElementTypeFormBase.php \Drupal\webform_ui\Form\WebformUiElementTypeFormBase::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 FormInterface::buildForm

2 calls to WebformUiElementTypeFormBase::buildForm()
WebformUiElementTypeChangeForm::buildForm in modules/webform_ui/src/Form/WebformUiElementTypeChangeForm.php
Form constructor.
WebformUiElementTypeSelectForm::buildForm in modules/webform_ui/src/Form/WebformUiElementTypeSelectForm.php
Form constructor.
2 methods override WebformUiElementTypeFormBase::buildForm()
WebformUiElementTypeChangeForm::buildForm in modules/webform_ui/src/Form/WebformUiElementTypeChangeForm.php
Form constructor.
WebformUiElementTypeSelectForm::buildForm in modules/webform_ui/src/Form/WebformUiElementTypeSelectForm.php
Form constructor.

File

modules/webform_ui/src/Form/WebformUiElementTypeFormBase.php, line 77

Class

WebformUiElementTypeFormBase
Provides a abstract element type webform for a webform element.

Namespace

Drupal\webform_ui\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, WebformInterface $webform = NULL) {
  $form['#prefix'] = '<div id="webform-ui-element-type-ajax-wrapper">';
  $form['#suffix'] = '</div>';
  $form['#attached']['library'][] = 'webform/webform.admin';
  $form['#attached']['library'][] = 'webform/webform.form';
  $form['#attached']['library'][] = 'webform/webform.tooltip';
  $form['#attached']['library'][] = 'webform_ui/webform_ui';
  if (!$this
    ->isOffCanvasDialog()) {
    $form['preview'] = [
      '#type' => 'submit',
      '#validate' => [
        '::noValidate',
      ],
      '#limit_validation_errors' => [],
      '#value' => $this
        ->isPreviewEnabled() ? $this
        ->t('Hide preview') : $this
        ->t('Show preview'),
      '#attributes' => [
        'class' => [
          'button--small',
        ],
        'style' => 'float: right;',
      ],
      '#ajax' => [
        'callback' => '::submitAjaxForm',
        'event' => 'click',
        'progress' => [
          'type' => 'fullscreen',
        ],
      ],
    ];
  }
  $form['filter'] = [
    '#type' => 'search',
    '#title' => $this
      ->t('Filter'),
    '#title_display' => 'invisible',
    '#size' => 30,
    '#placeholder' => $this
      ->t('Filter by element name'),
    '#attributes' => [
      'class' => [
        'webform-form-filter-text',
      ],
      'data-element' => '.webform-ui-element-type-table',
      'data-item-singlular' => $this
        ->t('element'),
      'data-item-plural' => $this
        ->t('elements'),
      'data-no-results' => '.webform-element-no-results',
      'title' => $this
        ->t('Enter a part of the element name to filter by.'),
      'autofocus' => 'autofocus',
    ],
  ];

  // No results.
  $form['no_results'] = [
    '#type' => 'webform_message',
    '#message_message' => $this
      ->t('No elements found. Try a different search.'),
    '#message_type' => 'info',
    '#attributes' => [
      'class' => [
        'webform-element-no-results',
      ],
    ],
    '#weight' => 1000,
  ];
  return $form;
}