public function WebformEntityAddForm::form in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformEntityAddForm.php \Drupal\webform\WebformEntityAddForm::form()
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/
WebformEntityAddForm.php, line 90
Class
- WebformEntityAddForm
- Provides a webform add form.
Namespace
Drupal\webformCode
public function form(array $form, FormStateInterface $form_state) {
/** @var \Drupal\webform\WebformInterface $webform */
$webform = $this
->getEntity();
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $webform
->id(),
'#machine_name' => [
'exists' => '\\Drupal\\webform\\Entity\\Webform::load',
'source' => [
'title',
],
'label' => '<br/>' . $this
->t('Machine name'),
],
'#maxlength' => 32,
'#field_suffix' => ' (' . $this
->t('Maximum @max characters', [
'@max' => 32,
]) . ')',
'#disabled' => (bool) ($webform
->id() && $this->operation !== 'duplicate'),
'#required' => TRUE,
];
$form['title'] = [
'#type' => 'textfield',
'#title' => $this
->t('Title'),
'#maxlength' => 255,
'#default_value' => $webform
->label(),
'#required' => TRUE,
'#id' => 'title',
'#attributes' => [
'autofocus' => 'autofocus',
],
];
$form['description'] = [
'#type' => 'webform_html_editor',
'#title' => $this
->t('Administrative description'),
'#default_value' => $webform
->get('description'),
];
/** @var \Drupal\webform\WebformEntityStorageInterface $webform_storage */
$webform_storage = $this->entityTypeManager
->getStorage('webform');
$form['category'] = [
'#type' => 'webform_select_other',
'#title' => $this
->t('Category'),
'#options' => $webform_storage
->getCategories(),
'#empty_option' => $this
->t('- None -'),
'#default_value' => $webform
->get('category'),
];
$form['status'] = [
'#type' => 'radios',
'#title' => $this
->t('Status'),
'#default_value' => $webform
->get('status'),
'#options' => [
WebformInterface::STATUS_OPEN => $this
->t('Open'),
WebformInterface::STATUS_CLOSED => $this
->t('Closed'),
],
'#options_display' => 'side_by_side',
];
$form = $this
->protectBundleIdElement($form);
return parent::form($form, $form_state);
}