public function addAction($request)
 {
     $title = $request->getPost('name');
     $parent = $request->getPost('parent');
     if (empty($title)) {
         $this->sendErrorHeader($this->t('Name cannot be empty.'));
     }
     $filename = FilesystemHelper::sanitizeFilename($title);
     #$parent = FilesystemHelper::sanitizeFilename($parent);
     $parentRoute = $this->getPageTree()->findByRoute($parent);
     if ($parentRoute->isRoot()) {
         $filepath = $this->alias->get("@page/{$filename}.md");
     } else {
         $parentAlias = dirname($parentRoute->getMenuItem()->getPath());
         $filepath = $this->alias->get("{$parentAlias}/{$filename}.md");
     }
     if (is_file($filepath)) {
         $this->sendErrorHeader($this->t('A page with the same name already exists.'));
     }
     $eol = PHP_EOL;
     $pageTitle = $this->t('My new page');
     $data = "---{$eol}title: {$title}{$eol}disabled: 1{$eol}hidden: 1{$eol}---{$eol}{$pageTitle}{$eol}";
     if (!file_put_contents($filepath, $data)) {
         $this->sendErrorHeader($this->t('Page {name} can not be created.', ['{name}' => $title]));
     }
     if (!empty($parent)) {
         $request->setQuery('route', $parent);
     }
     return $this->indexAction($request);
 }
 public function addAction($request)
 {
     $title = $request->getPost('name');
     if (empty($title)) {
         $this->sendErrorHeader($this->t('Name cannot be empty.'));
     }
     $filename = date('Y-m-d-') . FilesystemHelper::sanitizeFilename($title);
     $filepath = $this->alias->get("@post/{$filename}.md");
     if (is_file($filepath)) {
         $this->sendErrorHeader($this->t('A page with the same name already exists.'));
     }
     $eol = PHP_EOL;
     $pageTitle = $this->t('My new blog post');
     $data = "---{$eol}title: {$title}{$eol}disabled: 1{$eol}hidden: 1{$eol}---{$eol}{$pageTitle}{$eol}";
     if (!file_put_contents($filepath, $data)) {
         $this->sendErrorHeader($this->t('Page {name} can not be created.', ['{name}' => $title]));
     }
     return $this->indexAction();
 }