Skip to content

Commit

Permalink
Merge pull request #36 from xima-media/v13
Browse files Browse the repository at this point in the history
TYPO3 v13 support
  • Loading branch information
maikschneider authored Dec 16, 2024
2 parents 483641a + b178f49 commit 023aeea
Show file tree
Hide file tree
Showing 52 changed files with 743 additions and 904 deletions.
28 changes: 9 additions & 19 deletions .ddev/commands/web/init-typo3
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ readonly dbCredentials="-h${dbHost} -u${dbUser} -p${dbPassword}"
readonly fixturePath="/var/www/html/Tests/Acceptance/Fixtures"
readonly typo3Binary="/var/www/html/vendor/bin/typo3"
readonly typo3cmsBinary="/var/www/html/vendor/bin/typo3cms"
readonly typo3MainSitePath="/var/www/html/config/sites/main"

function _progress() {
printf "%s... " "$1"
Expand Down Expand Up @@ -43,28 +44,10 @@ export TYPO3_SETUP_ADMIN_PASSWORD=Passw0rd!
export TYPO3_SERVER_TYPE=apache
export TYPO3_PROJECT_NAME="EXT:xm_formcycle"

export TYPO3_INSTALL_DB_DRIVER=mysqli
export TYPO3_INSTALL_DB_USER="$dbUser"
export TYPO3_INSTALL_DB_PASSWORD="$dbPassword"
export TYPO3_INSTALL_DB_PORT=3306
export TYPO3_INSTALL_DB_HOST="$dbHost"
export TYPO3_INSTALL_DB_DBNAME="$dbName"
export TYPO3_INSTALL_ADMIN_USER=admin
export TYPO3_INSTALL_ADMIN_PASSWORD=Passw0rd!
export TYPO3_INSTALL_SITE_SETUP_TYPE="no"
export TYPO3_INSTALL_WEB_SERVER_CONFIG="apache"
export TYPO3_INSTALL_SITE_NAME="EXT:xm_formcycle"
export TYPO3_INSTALL_DB_UNIX_SOCKET=""

# Set up environment
_progress "Setting up TYPO3 installation"
# TYPO3 v11
if [ -f "$typo3cmsBinary" ]; then
"$typo3cmsBinary" install:setup --force --database-host-name="db" --database-user-name="db" --database-user-password="db" --database-name="db" --use-existing-database --admin-user-name="admin" --admin-password="Passw0rd!"
"$typo3cmsBinary" configuration:set SYS/trustedHostsPattern ".*"
else
"$typo3Binary" setup --no-interaction --force --quiet
fi
"$typo3Binary" configuration:set SYS/trustedHostsPattern ".*"
_done

# Import DB fixtures
Expand All @@ -73,3 +56,10 @@ for file in "$fixturePath"/*.sql; do
mysql $dbCredentials "$dbName" < "$file"
_done
done

# Copy site settings
_progress "Copying site settings"
mkdir -p $typo3MainSitePath
cp $fixturePath/sites/main/config.yaml $typo3MainSitePath/
cp $fixturePath/sites/main/settings.yaml $typo3MainSitePath/
_done
2 changes: 1 addition & 1 deletion .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: xm-formcycle
type: typo3
docroot: public
php_version: "8.1"
php_version: "8.2"
webserver_type: apache-fpm
router_http_port: "80"
router_https_port: "443"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
strategy:
fail-fast: false
matrix:
typo3-version: [ "11.5.37", "12.4" ]
php-version: [ "8.1", "8.2", "8.3" ]
typo3-version: [ "13.4.1" ]
php-version: [ "8.2", "8.3", "8.4" ]

steps:
- uses: actions/checkout@v4
Expand Down
12 changes: 5 additions & 7 deletions Classes/ContentSecurityPolicy/EventListener/FrontendListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\Directive;
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\Event\PolicyMutatedEvent;
use TYPO3\CMS\Core\Security\ContentSecurityPolicy\UriValue;
use Xima\XmFormcycle\Service\FormcycleService;

final class FrontendListener
final readonly class FrontendListener
{
public function __construct(private readonly FormcycleService $formcycleService)
{
}

public function __invoke(PolicyMutatedEvent $event): void
{
if ($event->scope->type->isBackend()) {
return;
}

$formcycleUrl = $this->formcycleService->getCspUrl();
$formcycleUrl = $event->scope->site->getSettings()->get('formcycle.url') ?? '';
if (!$formcycleUrl) {
return;
}

$event->getCurrentPolicy()->extend(
Directive::ConnectSrc,
Expand Down
10 changes: 6 additions & 4 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use Xima\XmFormcycle\Form\Element\FormcycleSelection;
use Xima\XmFormcycle\Service\FormcycleService;
use Xima\XmFormcycle\Service\FormcycleServiceFactory;

final class BackendController
{
public function __construct(
private readonly ResponseFactoryInterface $responseFactory,
private readonly FormcycleService $formcycleService
private readonly FormcycleServiceFactory $formcycleServiceFactory
) {
}

public function reloadAvailableForms(ServerRequestInterface $request): ResponseInterface
{
$this->formcycleService->resetAvailableFormsCache();
$pageUid = $request->getQueryParams()['pageUid'] ?? 0;
$this->formcycleServiceFactory->createFromPageUid($pageUid)->resetAvailableFormsCache();

return $this->getAvailableForms($request);
}

public function getAvailableForms(ServerRequestInterface $request): ResponseInterface
{
$forms = $this->formcycleService->getAvailableForms();
$pageUid = $request->getQueryParams()['pageUid'] ?? 0;
$forms = $this->formcycleServiceFactory->createFromPageUid($pageUid)->getAvailableForms();
$forms = FormcycleSelection::groupForms($forms);

$view = GeneralUtility::makeInstance(StandaloneView::class);
Expand Down
23 changes: 13 additions & 10 deletions Classes/DataProcessing/AbstractProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,41 @@

namespace Xima\XmFormcycle\DataProcessing;

use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
use Xima\XmFormcycle\Dto\ElementSettings;
use Xima\XmFormcycle\Dto\IntegrationMode;
use Xima\XmFormcycle\Service\FormcycleService;
use Xima\XmFormcycle\Service\FormcycleServiceFactory;

abstract class AbstractProcessor implements DataProcessorInterface
{
protected ElementSettings $settings;

protected FormcycleService $formcycleService;

public function __construct(private readonly FormcycleServiceFactory $formcycleServiceFactory)
{
}

public function process(
ContentObjectRenderer $cObj,
array $contentObjectConfiguration,
array $processorConfiguration,
array $processedData
) {
// construct element settings
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
$this->settings = ElementSettings::createFromContentElement(
$flexFormService,
$cObj,
);
$this->settings = ElementSettings::createFromContentElement($cObj);

$this->formcycleService = GeneralUtility::makeInstance(FormcycleService::class);
$this->formcycleService = $this->formcycleServiceFactory->createFromPageUid($cObj->data['pid']);

// check if integration mode is set
if ($this->settings->integrationMode === IntegrationMode::Default) {
$this->settings->integrationMode = $this->formcycleService->getDefaultIntegrationMode();
}

// check if concrete processor should be used
$currentIntegrationMode = $this->settings->integrationMode ?? $this->formcycleService->getDefaultIntegrationMode();
if ($currentIntegrationMode->forDataProcessing() !== $this->getIntegrationMode()) {
if ($this->settings->integrationMode->forDataProcessing() !== $this->getIntegrationMode()) {
return $processedData;
}

Expand Down
23 changes: 9 additions & 14 deletions Classes/Dto/ElementSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Xima\XmFormcycle\Dto;

use TYPO3\CMS\Core\Service\FlexFormService;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException;

Expand All @@ -14,37 +13,33 @@ class ElementSettings

public string $formId = '';

public ?IntegrationMode $integrationMode = null;
public IntegrationMode $integrationMode;

public bool $loadFormcycleJquery = true;

public bool $loadFormcycleJqueryUi = false;
public bool $loadFormcycleJqueryUi = true;

public string $additionalParameters = '';

public string $language = '';

public static function createFromContentElement(
FlexFormService $flexFormService,
ContentObjectRenderer $cObj,
): self {
$xml = $flexFormService->convertFlexFormContentToArray($cObj->data['pi_flexform'] ?? '');

$settings = new self();
$settings->formId = $cObj->data['tx_xmformcycle_form_id'] ?? '';

try {
$language = $cObj->getRequest()->getAttribute('language')->getTwoLetterIsoCode();
$settings->language = $language;
$settings->language = (string)$cObj->getRequest()->getAttribute('language')->getLocale();
} catch (\Error|ContentRenderingException) {
}

$settings->successPid = $xml['settings']['xf']['siteok'] ?? 0;
$settings->errorPid = $xml['settings']['xf']['siteerror'] ?? 0;
$settings->loadFormcycleJquery = (bool)($xml['settings']['xf']['useFcjQuery'] ?? 1);
$settings->loadFormcycleJqueryUi = (bool)($xml['settings']['xf']['useFcjQueryUi'] ?? 0);
$settings->additionalParameters = $xml['settings']['xf']['useFcUrlParams'] ?? '';
$settings->integrationMode = IntegrationMode::tryFrom($xml['settings']['xf']['integrationMode']);
$settings->successPid = $cObj->data['tx_xmformcycle_redirect_success'] ?? 0;
$settings->errorPid = $cObj->data['tx_xmformcycle_redirect_error'] ?? 0;
$settings->loadFormcycleJquery = (bool)($cObj->data['tx_xmformcycle_is_jquery'] ?? 1);
$settings->loadFormcycleJqueryUi = (bool)($cObj->data['tx_xmformcycle_is_jquery_ui'] ?? 1);
$settings->additionalParameters = $cObj->data['tx_xmformcycle_additional_params'] ?? '';
$settings->integrationMode = IntegrationMode::fromDatabase($cObj->data['tx_xmformcycle_integration_mode']);

return $settings;
}
Expand Down
63 changes: 0 additions & 63 deletions Classes/Dto/FormcycleConfiguration.php

This file was deleted.

34 changes: 34 additions & 0 deletions Classes/Dto/IntegrationMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,40 @@ enum IntegrationMode: string
case AjaxTypo3 = 'AJAX (TYPO3)';
case AjaxFormcycle = 'AJAX (FORMCYCLE)';

case Default = 'Default';

public static function fromDatabase($value): self
{
return match ($value) {
1 => self::Integrated,
2 => self::AjaxTypo3,
3 => self::AjaxFormcycle,
4 => self::Iframe,
default => self::Default,
};
}

public function forDatabase(): int
{
return match ($this) {
self::Integrated => 1,
self::AjaxTypo3 => 2,
self::AjaxFormcycle => 3,
self::Iframe => 4,
default => 0,
};
}

public static function fromSiteSettings($value): self
{
return match ($value) {
'iframe' => self::Iframe,
'ajax_typo3' => self::AjaxTypo3,
'ajax_formcycle' => self::AjaxFormcycle,
default => self::Integrated,
};
}

public function forDataProcessing(): self
{
if ($this === self::AjaxTypo3 || $this === self::AjaxFormcycle) {
Expand Down
Loading

0 comments on commit 023aeea

Please sign in to comment.