Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Classes/ContextMenu/ItemProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace SUDHAUS7\Sudhaus7Wizard\ContextMenu;

use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider;
use TYPO3\CMS\Backend\Utility\BackendUtility;

final class ItemProvider extends AbstractProvider
{
protected $itemsConfiguration = [
's7wizard' => [
'type' => 'item',
'label' => 'Create new from page...', // you can use "LLL:" syntax here
'iconIdentifier' => 'actions-document-info',
'callbackAction' => 'createTask', //name of the function in the JS file
],
];

public function getPriority(): int
{
return 90;
}

public function canHandle(): bool
{
return $this->table === 'pages';
}

public function addItems(array $items): array
{
$this->initDisabledItems();
$localItems = $this->prepareItems($this->itemsConfiguration);
$items = $items + $localItems;
return $items;
}

protected function getAdditionalAttributes(string $itemName): array
{
return [
'data-callback-module' => 'TYPO3/CMS/Sudhaus7Wizard/CreateWizardTaskWizard',
];
}

protected function canRender(string $itemName, string $type): bool
{
if (in_array($itemName, $this->disabledItems, true)) {
return false;
}

$canRender = false;
if ($itemName == 's7wizard') {
$canRender = $this->isSiteRoot();
}
return $canRender;
}

private function isSiteRoot(): bool
{
$pageRecord = BackendUtility::getRecord('pages', $this->identifier);
return ($pageRecord['is_siteroot'] ?? 0) === 1;
}
}
169 changes: 169 additions & 0 deletions Classes/Controller/Backend/CreateNewTaskAjaxController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php

declare(strict_types=1);

namespace SUDHAUS7\Sudhaus7Wizard\Controller\Backend;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use SUDHAUS7\Sudhaus7Wizard\Interfaces\WizardProcessInterface;
use SUDHAUS7\Sudhaus7Wizard\Interfaces\WizardTemplateConfigInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;

final class CreateNewTaskAjaxController
{
private UriBuilder $uriBuilder;

public function __construct(
UriBuilder $uriBuilder
) {
$this->uriBuilder = $uriBuilder;
}

public function getTemplatesAction(ServerRequestInterface $request): ResponseInterface
{
$templates = [];

/** @var WizardProcessInterface $registeredTemplateExtention */
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['Sudhaus7Wizard']['registeredTemplateExtentions'] ?? [] as $registeredTemplateExtension) {
/** @var WizardTemplateConfigInterface $configuration */
$configuration = $registeredTemplateExtension::getWizardConfig();
$templates[] = [
'title' => $configuration->getDescription(),
'value' => $configuration->getExtension(),
];
}

$success = count($templates) > 0;

$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename('EXT:sudhaus7_wizard/Resources/Private/Templates/Backend/GetTemplates.html');
$view->assign('templates', $templates);

$data = [
'success' => $success,
'templates' => $templates,
'html' => $view->render(),
];

return new JsonResponse($data);
}

public function getGeneralFieldsAction(ServerRequestInterface $request): ResponseInterface
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename('EXT:sudhaus7_wizard/Resources/Private/Templates/Backend/GeneralFields.html');
$data = [
'html' => $view->render(),
];

return new JsonResponse($data);
}

public function getEditorFieldsAction(ServerRequestInterface $request): ResponseInterface
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename('EXT:sudhaus7_wizard/Resources/Private/Templates/Backend/EditorFields.html');
$data = [
'html' => $view->render(),
];

return new JsonResponse($data);
}

public function getTemplateFieldsAction(ServerRequestInterface $request): ResponseInterface
{
/** @var WizardProcessInterface|null $template */
$template = $request->getQueryParams()['template'] ?? null;
if ($template === null || !in_array(WizardProcessInterface::class, class_implements($template), true)) {
$data = [
'success' => false,
];

return new JsonResponse($data);
}
$configuration = $template::getWizardConfig();
$flexInfoFile = $configuration->getFlexinfoFile();
if (!empty($flexInfoFile)) {
$realPathToFlexFile = GeneralUtility::getFileAbsFileName($flexInfoFile);
// @todo render/prepare Flex
}
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename('EXT:sudhaus7_wizard/Resources/Private/Templates/Backend/TemplateFields.html');
$data = [
'html' => $view->render(),
];

return new JsonResponse($data);
}

public function createNewTask(ServerRequestInterface $request): ResponseInterface
{
$wizard = $this->getParamsFromRequest($request)['wizard'] ?? [];
$wizard['pid'] = 0;
$newWizardIdentifier = StringUtility::getUniqueId('NEW');
$data = [
'tx_sudhaus7wizard_domain_model_creator' => [
$newWizardIdentifier => $wizard,
],
];

$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start($data, []);
$dataHandler->process_datamap();
if ($dataHandler->errorLog !== []) {
$returnData = [
'success' => false,
'error' => [],
];
foreach ($dataHandler->errorLog as $errorLog) {
$returnData['error'][] = $errorLog;
}
return new JsonResponse($returnData);
}

$newWizardTaskId = $dataHandler->substNEWwithIDs[$newWizardIdentifier];

$redirectUri = $this->uriBuilder
->buildUriFromRoute(
'record_edit',
[
'edit' => [
'tt_address' => [
$newWizardTaskId => 'edit',
],
],
]
);
$returnData = [
'success' => true,
'redirectUrl' => (string)$redirectUri,
];
return new JsonResponse($returnData);
}

/**
* @return array<array-key, mixed>
*/
protected function getParamsFromRequest(ServerRequestInterface $request): array
{
$postParams = $request->getParsedBody();

try {
$postArrayParams = match (gettype($postParams)) {
'array' => $postParams,
'object' => json_decode(json_encode($postParams) ?: '{}', true, 512, JSON_THROW_ON_ERROR),
default => []
};
} catch (\JsonException $_) {
$postArrayParams = [];
}

return $postArrayParams;
}
}
23 changes: 23 additions & 0 deletions Configuration/Backend/AjaxRoutes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

use SUDHAUS7\Sudhaus7Wizard\Controller\Backend\CreateNewTaskAjaxController;

return [
's7wizardGetTemplates' => [
'path' => '/s7wizard/getTemplates',
'method' => ['GET'],
'target' => CreateNewTaskAjaxController::class . '::getTemplatesAction',
],
's7wizardGetGeneralFields' => [
'path' => '/s7wizard/getGeneralFields',
'method' => ['GET'],
'target' => CreateNewTaskAjaxController::class . '::getGeneralFieldsAction',
],
's7wizardGetEditorFields' => [
'path' => '/s7wizard/getEditorFields',
'method' => ['GET'],
'target' => CreateNewTaskAjaxController::class . '::getEditorFieldsAction',
],
];
5 changes: 5 additions & 0 deletions Configuration/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/

use SUDHAUS7\Sudhaus7Wizard\Cli\RunCommand;
use SUDHAUS7\Sudhaus7Wizard\Controller\Backend\CreateNewTaskAjaxController;
use SUDHAUS7\Sudhaus7Wizard\EventHandlers\DefaultSiteSorterListener;
use SUDHAUS7\Sudhaus7Wizard\EventHandlers\Extensions\TxNewsFixRecordHandler;
use SUDHAUS7\Sudhaus7Wizard\EventHandlers\Extensions\TxNewsPluginHandlerEvent;
Expand All @@ -38,6 +39,7 @@
__DIR__ . '/../Classes/Domain/Model/',
__DIR__ . '/../Classes/Events/',
__DIR__ . '/../Classes/Backend/',
__DIR__ . '/../Classes/ContextMenu/',
]);

$services->alias(SourceInterface::class, LocalDatabase::class);
Expand All @@ -48,6 +50,9 @@
'schedulable' => true,
]);

$services->set(CreateNewTaskAjaxController::class)
->public();

$services->set(PreSysFileReferenceEventHandler::class)
->tag('event.listener', ['identifier' => 's7wizardBaseHandleSysFileReferences']);

Expand Down
Empty file.
28 changes: 28 additions & 0 deletions Resources/Private/Templates/Backend/EditorFields.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html
data-namespace-typo3-fluid="true"
lang="en"
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
>
<form id="editorWizardForm">
<div class="form-group">
<label for="username">
Editor username
</label>
<input class="form-control" type="text" name="wizard[reduser]" id="username" required>
</div>
<div class="form-group">
<label for="password">
Editor Password (Min. 8 Zeichen)
</label>
<input class="form-control" type="text" name="wizard[password]" minlength="8" id="password" required>
</div>
<div class="form-group">
<label for="email">
Editor E-Mail
</label>
<input class="form-control" type="email" name="wizard[redemail]" id="email" required>
</div>
</form>
</html>
40 changes: 40 additions & 0 deletions Resources/Private/Templates/Backend/GeneralFields.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<html
data-namespace-typo3-fluid="true"
lang="en"
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
>
<form id="generalWizardForm">
<div class="form-group">
<label for="projectname">
Projektname / Kunde (wird intern im System verwendet)
</label>
<input class="form-control" type="text" name="wizard[projektname]" id="projectname" required>
</div>
<div class="form-group">
<label for="longname">
Name des Auftritts (Website Titel)
</label>
<input class="form-control" type="text" name="wizard[longname]" id="longname" required>
</div>
<div class="form-group">
<label for="shortname">
Kurzname (für fileadmin, erlaubte Zeichen: A-Z, a-z, 0-9, _
</label>
<input class="form-control" type="text" name="wizard[shortname]" id="shortname" required>
</div>
<div class="form-group">
<label for="url">
URL des Auftritts (ohne http:// oder https://)
</label>
<input class="form-control" type="text" pattern="^[\w\.\-]*\.(\w{2,3})$" name="wizard[url]" id="url" required>
</div>
<div class="form-group">
<label for="contact">
Kontakt E-Mail
</label>
<input class="form-control" type="email" name="wizard[contact]" id="contact" required>
</div>
</form>
</html>
28 changes: 28 additions & 0 deletions Resources/Private/Templates/Backend/GetTemplates.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html
data-namespace-typo3-fluid="true"
lang="en"
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
>
<div class="form-group">
<label for="selectTemplate">
Select Template
</label>
<select class="form-select" id="selectTemplate" name="base">
<option value="">
Please choose
</option>
<f:for each="{templates}" as="template">
<f:if condition="{selectedTemplate} == {template.value}">
<f:then>
<option selected value="{template.value}">{template.title}</option>
</f:then>
<f:else>
<option value="{template.value}">{template.title}</option>
</f:else>
</f:if>
</f:for>
</select>
</div>
</html>
Loading