You are here

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

1 call to N1EDSelfHosted::rebuildDependencies()
N1EDSelfHosted::setSelfHostedConfig in src/Controller/N1EDSelfHosted.php

File

src/Controller/N1EDSelfHosted.php, line 26

Class

N1EDSelfHosted

Namespace

Drupal\n1ed\Controller

Code

public function rebuildDependencies() : void {
  $plugin_file = file_get_contents($this->plugin_file);
  preg_match('/\\/\\*N1ED-ECO-CONFIG-START\\*\\/(.*?)\\/\\*N1ED-ECO-CONFIG-END\\*\\//s', $plugin_file, $match);
  if ($match[1]) {
    $n1ed_conf = json_decode($match[1], true);
  }
  $plugins = [];
  foreach ($this
    ->getPluginsAvailable() as $plugin_name) {
    if (array_key_exists('enabled' . $plugin_name, $n1ed_conf)) {
      $plugins[$plugin_name] = $n1ed_conf['enabled' . $plugin_name] ? $this->self_hosted_URL . '/' . $plugin_name . '/plugin.js' : null;
    }
    else {
      $plugins[$plugin_name] = $this->self_hosted_URL . '/' . $plugin_name . '/plugin.js';
    }
  }
  $search = '/\\/\\*N1ED-ECO-DEPENDENCIES-START\\*\\/(.*?)\\/\\*N1ED-ECO-DEPENDENCIES-END\\*\\//s';
  $replace = "/*N1ED-ECO-DEPENDENCIES-START*/" . json_encode($plugins) . "/*N1ED-ECO-DEPENDENCIES-END*/";
  $new_plugin = preg_replace($search, $replace, $plugin_file);
  file_put_contents($this->plugin_file, $new_plugin);
}