Skip to content
Merged
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
54 changes: 54 additions & 0 deletions Classes/Controller/ValidationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Controller;

use Kitodo\Dlf\Validation\Configuration\YamlConfigurationProvider;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Plugin 'Validation' for the 'dlf' extension
*
* @package TYPO3
* @subpackage dlf
*
* @access public
*/
class ValidationController extends AbstractController
{
/**
* @access public
*
* @return ResponseInterface the response
*/
public function mainAction(): ResponseInterface
{
$validationConfiguration = GeneralUtility::makeInstance(YamlConfigurationProvider::class)->getConfiguration($this->settings['type']);

/** @var SiteLanguage $siteLanguage */
$siteLanguage = $this->request->getAttribute('language') ?? $this->request->getAttribute('site')->getDefaultLanguage();

$disabledValidators = [];
foreach ($validationConfiguration as $key => $value) {
if (isset($value['disabled']) && $value['disabled'] === "true") {
$disabledValidators[$key]['title'] = $value['title'];
$disabledValidators[$key]['shortDescription'] = $value['shortDescription'];
}
}

$this->view->assign("url", $siteLanguage->getBase()->getPath() . '?middleware=dlf/dom-document-validation');
$this->view->assign("disabledValidators", $disabledValidators);
return $this->htmlResponse();
}
}
67 changes: 0 additions & 67 deletions Classes/Controller/ValidationFormController.php

This file was deleted.

23 changes: 6 additions & 17 deletions Classes/Middleware/DOMDocumentValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use DOMDocument;
use Exception;
use InvalidArgumentException;
use Kitodo\Dlf\Validation\Configuration\YamlConfigurationProvider;
use Kitodo\Dlf\Validation\DOMDocumentValidationStack;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -46,7 +47,6 @@ class DOMDocumentValidation implements MiddlewareInterface

private const BAD_REQUEST = 400;
private const NOT_FOUND = 404;
private const INTERNAL_SERVER_ERROR = 500;

private ServerRequestInterface $request;

Expand Down Expand Up @@ -84,6 +84,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
if ($typeParam === null) {
return $this->getJsonResponse('Validation type parameter is missing.', self::BAD_REQUEST);
}

// load dom document from url
if (!GeneralUtility::isValidUrl($urlParam)) {
return $this->getJsonResponse('Parameter "' . $urlParam . '" is not a valid URL.', self::NOT_FOUND);
Expand All @@ -104,26 +105,14 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
return $this->getJsonResponse("Content from the URL is not valid XML.", self::BAD_REQUEST);
}

// retrieve validation configuration from plugin.tx_dlf typoscript
/** @var ConfigurationManagerInterface $configurationManager */
$configurationManager = GeneralUtility::makeInstance(ConfigurationManagerInterface::class);
$typoScript = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);

/** @var TypoScriptService $typoScriptService */
$typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$settings = $typoScriptService->convertTypoScriptArrayToPlainArray($typoScript['plugin.']['tx_dlf.']['settings.']);

if (!array_key_exists("domDocumentValidation", $settings)) {
$this->logger->error('DOMDocumentValidation is not configured.');
return $this->getJsonResponse('An internal server error occurred.', self::INTERNAL_SERVER_ERROR);
}
$validationConfiguration = GeneralUtility::makeInstance(YamlConfigurationProvider::class)->getConfiguration($typeParam);

if (!array_key_exists($typeParam, $settings["domDocumentValidation"])) {
if (empty($validationConfiguration)) {
$this->logger->debug('Validation configuration type in validationType parameter "' . $typeParam . '" does not exist.');
return $this->getJsonResponse('Validation type does not exist.', self::NOT_FOUND);
return $this->getJsonResponse('Validation type parameter does not exist.', self::NOT_FOUND);
}

$validationConfiguration = $this->removeDisabledValidators($parameters, $settings['domDocumentValidation'][$typeParam]);
$validationConfiguration = $this->removeDisabledValidators($parameters, $validationConfiguration);

$validation = GeneralUtility::makeInstance(DOMDocumentValidationStack::class, $validationConfiguration);

Expand Down
78 changes: 78 additions & 0 deletions Classes/Validation/Configuration/YamlConfigurationProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Validation\Configuration;

use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader;
use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class YamlConfigurationProvider
{

/**
* @access private
* @var Logger This holds the logger
*/
private Logger $logger;

/**
* @access private
* @var ?PackageManager This holds the package manager
*/
private ?PackageManager $packageManager;

/**
* @access private
* @var ?YamlFileLoader This holds the YAML file loader
*/
private ?YamlFileLoader $yamlFileLoader;

/**
* Constructs the Reader instance
*
* @access public
*
* @param ?PackageManager $packageManager The package manager
* @param ?YamlFileLoader $yamlFileLoader The YAML file loader
*
* @return void
*/
public function __construct(?PackageManager $packageManager = null, ?YamlFileLoader $yamlFileLoader = null)
{
$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(static::class);
$this->packageManager = $packageManager ?? GeneralUtility::makeInstance(PackageManager::class);
$this->yamlFileLoader = $yamlFileLoader ?? GeneralUtility::makeInstance(YamlFileLoader::class);
}

/**
* @return array<int, array<string, mixed>>
*/
public function getConfiguration(string $type): array
{
foreach ($this->packageManager->getActivePackages() as $package) {
$packagePath = rtrim($package->getPackagePath(), '/');
$configurationFile = $packagePath . '/Configuration/Kitodo/Validation/' . $type . '.yaml';
if (is_file($configurationFile)) {
$configuration = $this->yamlFileLoader->load($configurationFile);
if (is_array($configuration)) {
return $configuration;
} else {
$this->logger->error('Invalid configuration file: ' . $configurationFile);
}
}
}
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<el>
<settings.type>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:validationForm.flexForm.type.label</label>
<description>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:validationForm.flexForm.type.description</description>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:validation.flexForm.type.label</label>
<description>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:validation.flexForm.type.description</description>
<config>
<type>input</type>
<eval>required,trim</eval>
Expand Down
14 changes: 7 additions & 7 deletions Configuration/TCA/Overrides/tt_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,22 @@
$iconsDirectory . 'tx-dlf-embedded3dviewer.svg'
);

// Plugin "validationform".
$plugin = 'dlf_validationform';
// Plugin "validation".
$plugin = 'dlf_validation';

$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist'][$plugin] = $excludeList;
$GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$plugin] = $addList;

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
'dlf_validationform',
$flexFormsPathPrefix . 'ValidationForm.xml'
'dlf_validation',
$flexFormsPathPrefix . 'Validation.xml'
);

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Dlf',
'ValidationForm',
$langFile . 'validationForm' . $title,
$iconsDirectory . 'tx-dlf-validationform.svg'
'Validation',
$langFile . 'validation' . $title,
$iconsDirectory . 'tx-dlf-validation.svg'
);

// Plugin "feeds".
Expand Down
10 changes: 5 additions & 5 deletions Configuration/TsConfig/ContentElements.tsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ mod.wizards.newContentElement.wizardItems {
list_type = dlf_toolbox
}
}
tx_dlf_validationform {
iconIdentifier = tx-dlf-validationform
title = LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:validationForm.plugin.title
description = LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:validationForm.plugin.description
tx_dlf_validation {
iconIdentifier = tx-dlf-validation
title = LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:validation.plugin.title
description = LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:validation.plugin.description
tt_content_defValues {
CType = list
list_type = dlf_validationform
list_type = dlf_validation
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ page {
}

includeJSFooter {
# ValidationForm plugin
kitodo-validationForm = EXT:dlf/Resources/Public/JavaScript/ValidationForm/ValidationForm.js
# Validation plugin
kitodo-validation = EXT:dlf/Resources/Public/JavaScript/Validation/Validation.js

# Verovio plugin
kitodo-verovio = EXT:dlf/Resources/Public/JavaScript/Verovio/verovio-toolkit-wasm.js
Expand Down
Loading
Loading