public function WebformUiElementEditForm::buildForm in Webform 8.5
Same name and namespace in other branches
- 6.x modules/webform_ui/src/Form/WebformUiElementEditForm.php \Drupal\webform_ui\Form\WebformUiElementEditForm::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/ WebformUiElementEditForm.php, line 26
Class
- WebformUiElementEditForm
- Provides an edit 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->element = $webform
->getElementDecoded($key);
if ($this->element === NULL) {
throw new NotFoundHttpException();
}
// Handler changing element type.
if ($type = $this
->getRequest()
->get('type')) {
$webform_element = $this
->getWebformElementPlugin();
$related_types = $webform_element
->getRelatedTypes($this->element);
if (!isset($related_types[$type])) {
throw new NotFoundHttpException();
}
$this->originalType = $this->element['#type'];
$this->element['#type'] = $type;
}
// Issue: #title is display as modal dialog's title and can't be escaped.
// Workaround: Filter and define @title as safe markup.
$title = WebformElementHelper::getAdminTitle($this->element);
$form['#title'] = $this
->t('Edit @title element', [
'@title' => Markup::create(Xss::filterAdmin($title)),
]);
$this->action = $this
->t('updated');
$form = parent::buildForm($form, $form_state, $webform, $key);
// Delete action.
if (!$form_state
->get('default_value_element')) {
$url = new Url('entity.webform_ui.element.delete_form', [
'webform' => $webform
->id(),
'key' => $key,
]);
$this
->buildDialogDeleteAction($form, $form_state, $url);
}
return $form;
}