Change site name programmatically We have a requirement that when we save a node that nodes title should be the site name. We used to do it in Drupal 7. But I was not able to find the proper method for it in Drupal 8.

This is what we tried:

$config = \Drupal::service('config.factory')-&gt;getEditable('system.site');
$config-&gt;set('system.site.name', "Demo Site");
$config-&gt;save();


Got it from here: https://www.drupal.org/docs/8/api/configuration-api/simple-configuration-api

Any suggestions?
Nearly :

$config = \Drupal::service('config.factory')-&gt;getEditable('system.site');
$config-&gt;set('name', "XXXXXXX"); 
$config-&gt;save();


Just have to implement hook_node_update to fit your needs.