Skip to content

Commit

Permalink
Merge pull request #3 from lindesbs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
lindesbs authored Jun 3, 2023
2 parents 060146b + caaf3e5 commit 4ab7cdc
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/Controller/BackendImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace lindesbs\pageyaml\Controller;

use Contao\Controller;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\Input;
use Contao\PageModel;
use Contao\StringUtil;
use Contao\System;
use Doctrine\DBAL\Connection;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Yaml\Yaml;
Expand Down Expand Up @@ -39,7 +41,10 @@ public function renderForm(): string
$this->framework->initialize();
$request = $this->requestStack->getCurrentRequest();

$this->handlePOSTData($request);
if ($this->handlePOSTData($request))
{
Controller::redirect('contao?do=page');
}

$strFileSelections = $this->getYamlFiles();

Expand All @@ -58,7 +63,7 @@ public function renderForm(): string
}


protected function walk($pageKey, $pageData, $pid = 0)
protected function walk($pageKey, $pageData, $pid = 0): void
{
$alias = null;

Expand Down Expand Up @@ -89,19 +94,31 @@ protected function walk($pageKey, $pageData, $pid = 0)
}
$objPage->published = true;

$nodes = [];
// Ist die Bezeichnung numerisch, wird dies als Errorpage gewertet
if (is_int($pageKey))
{
$objPage->type = 'error_'.$pageKey;
}

$nodes = [];

if (is_array($pageData)) {
foreach ($pageData as $arrayKey => $arrayValue) {

if (str_starts_with($arrayKey, '~')) {
$key = ltrim($arrayKey, '~');
$objPage->$key = $arrayValue;

continue;
}
else {
$nodes[$arrayKey] = $arrayValue;

if (str_starts_with($arrayKey,'_'))
{
$objPage->visible = true;
$objPage->hide = true;
}

$nodes[$arrayKey] = $arrayValue;
}
}

Expand Down Expand Up @@ -138,10 +155,10 @@ public function getYamlFiles(): array
}

/**
* @param \Symfony\Component\HttpFoundation\Request|null $request
* @return void
* @param Request|null $request
* @return bool
*/
public function handlePOSTData(?\Symfony\Component\HttpFoundation\Request $request): bool
public function handlePOSTData(?Request $request): bool
{
if (($request->getMethod() === 'POST') &&
($request->get('FORM_ID') === 'PAGEYAML_UPLOAD')) {
Expand All @@ -154,9 +171,10 @@ public function handlePOSTData(?\Symfony\Component\HttpFoundation\Request $reque

$this->walk(key($fileData), array_pop(array_values($fileData)));

return true;
}

return true;
return false;
}


Expand Down

0 comments on commit 4ab7cdc

Please sign in to comment.