How can I remove or overwrite the YAML validation from a Webform Entity?

by JDDoesDev   Last Updated June 12, 2019 15:07 PM

I am currently building a module that parses raw HTML into a webform using YAML, however I am running into an issue where the name='SomeName' on form elements is causing an error in the YAML keys.

The form relies on the name attribute in order to accurately map the data so I need it to be case insensitive. I can force a save programmatically with

$webform = new \Drupal\webform\Entity\Webform::create(
// stuff here
);

$webform->save();

However when someone attempts to edit the form in the UI and saves, there is an error preventing save that comes from docroot/modules/contrib/webform/src/WebformEntityElementsValidator.php

This error prevents saving due to casing errors.
The element key contact_Name on line 1 must contain only lowercase letters, numbers, and underscores.

The element key contact_Name on line 1 must contain only lowercase letters, numbers, and underscores.

I have tried

function MYMODULE_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $forms_array = ['webform_ui_element_form', 'webform_source_form'];
  if (in_array($form_id, $forms_array)) {
    $form['actions']['submit']['#limit_validation_errors'] = [];
    $form['actions']['submit']['#_validate_form'] = FALSE;
  }

}

However it seems that for some reason this prevents saving a new element.

Any help is appreciated.

Tags : webforms


Related Questions


Updated January 05, 2019 15:07 PM

Updated April 17, 2018 15:07 PM

Updated April 18, 2018 17:07 PM

Updated April 23, 2018 16:07 PM

Updated May 08, 2018 09:07 AM