You are here

public function N1EDSelfHosted::setSelfHostedConfig in N1ED - Visual editor as CKEditor plugin with Bootstrap support 8.2

File

src/Controller/N1EDSelfHosted.php, line 87

Class

N1EDSelfHosted

Namespace

Drupal\n1ed\Controller

Code

public function setSelfHostedConfig(string $new_config) : array {
  if ($this
    ->checkSelfHostedFiles()) {
    $plugin_file = file_get_contents($this->plugin_file);
    $search = '/\\/\\*N1ED-ECO-CONFIG-START\\*\\/(.*?)\\/\\*N1ED-ECO-CONFIG-END\\*\\//s';
    $replace = "/*N1ED-ECO-CONFIG-START*/" . $new_config . "/*N1ED-ECO-CONFIG-END*/";
    $new_plugin = preg_replace($search, $replace, $plugin_file);
    file_put_contents($this->plugin_file, $new_plugin);
    $this
      ->rebuildDependencies();
    return [
      'error' => null,
      'data' => 'ok',
    ];
  }
  else {
    return $this
      ->noFilesResponse();
  }
}