How To Alter Web Form Elements Permanently? Webform elements can be altered using the function MYMODULE_form_alter. However the changes are not permanent. For example, if you're changing the title of an element from '#title' =&gt; t('Old Title') to '#title' =&gt; t('New Title') ,the change will not affect source - the (View) Source page will still show '#title' =&gt; t('Old Title')
So my question is: Is it possible to alter the source (YAML) from code because that will make changes permanent.I have tried to locate weformX.yml for webformX inorder to alter it in code but I can not find.
You can alter the yaml source of a webform by loading the config entity and modify elements:

use Drupal\webform\Entity\Webform;
use Drupal\Core\Serialization\Yaml;

  $webform = Webform::load('contact');
  $elements = Yaml::decode($webform-&gt;get('elements'));
  $elements['name']['#title'] = 'Please fill in your name';
  $webform-&gt;set('elements', Yaml::encode($elements));
  $webform-&gt;save();