public function reformatFileAction($request) { $name = $request->getPost('name'); $files = $this->getYamlFiles(); if (empty($name) || !array_key_exists($name, $files)) { $this->sendErrorHeader($this->t('Invalid parameter!')); } if (!is_file($files[$name]['path'])) { $this->sendErrorHeader($this->t('{name} does not exist.', ['{name}' => $files[$name]['label']])); } if (!FilesystemHelper::createBackupFile($files[$name]['path'])) { $this->sendErrorHeader($this->t('Backup file can not be created.')); } $parsed = Yaml::parse($files[$name]['path']); $content = Yaml::dump($parsed); if (!file_put_contents($files[$name]['path'], $content)) { $this->sendErrorHeader($this->t('File can not be created.')); } echo $this->t('File was formatted and saved.'); exit; }