public function WebformUiElementAddForm::buildForm in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_ui/src/Form/WebformUiElementAddForm.php \Drupal\webform_ui\Form\WebformUiElementAddForm::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 WebformUiElementFormBase::buildForm
File
- modules/
webform_ui/ src/ Form/ WebformUiElementAddForm.php, line 22
Class
- WebformUiElementAddForm
- Provides an add webform for a webform element.
Namespace
Drupal\webform_ui\FormCode
public function buildForm(array $form, FormStateInterface $form_state, WebformInterface $webform = NULL, $key = NULL, $parent_key = NULL, $type = NULL) {
$this->webform = $webform;
$this->element['#type'] = $type;
$this->action = $this
->t('created');
$parent_key = $this
->getRequest()
->get('parent');
if ($parent_key) {
$parent_element = $webform
->getElement($parent_key);
if (!$parent_element) {
throw new NotFoundHttpException();
}
}
$element_plugin = $this
->getWebformElementPlugin();
$t_args = [
'@label' => $element_plugin
->getPluginLabel(),
];
if ($parent_key) {
$t_args['@parent'] = $parent_element['#admin_title'] ?: $parent_element['#title'] ?: $parent_element['#webform_key'];
$form['#title'] = $this
->t('Add @label element to "@parent"', $t_args);
}
else {
$form['#title'] = $this
->t('Add @label element', $t_args);
}
$form = parent::buildForm($form, $form_state, $webform, NULL, $parent_key);
if (isset($form['properties']['element']['title'])) {
$form['properties']['element']['title']['#attributes']['autofocus'] = 'autofocus';
}
return $form;
}