Merge pull request #565 from albig/documenttype-switch-symfonie-edition

Migrate DocumentType-Swith to Symfonie Expression Language.
This commit is contained in:
Sebastian Meyer 2020-12-12 12:29:39 +01:00 committed by GitHub
commit 3f7054568f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 247 additions and 1 deletions

View File

@ -0,0 +1,135 @@
<?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\ExpressionLanguage;
use Kitodo\Dlf\Common\Document;
use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\IiifManifest;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
/**
* Provider class for additional "getDocmentType" function to the ExpressionLanguage.
*
* @author Alexander Bigga <alexander.bigga@slub-dresden.de>
* @package TYPO3
* @subpackage dlf
* @access public
*/
class DocumentTypeFunctionProvider implements ExpressionFunctionProviderInterface
{
/**
* This holds the extension's parameter prefix
* @see \Kitodo\Dlf\Common\AbstractPlugin
*
* @var string
* @access protected
*/
protected $prefixId = 'tx_dlf';
/**
* @return ExpressionFunction[] An array of Function instances
*/
public function getFunctions()
{
return [
$this->getDocumentTypeFunction(),
];
}
/**
* Shortcut function to access field values
*
* @return \Symfony\Component\ExpressionLanguage\ExpressionFunction
*/
protected function getDocumentTypeFunction(): ExpressionFunction
{
return new ExpressionFunction(
'getDocumentType',
function () {
// Not implemented, we only use the evaluator
},
function ($arguments, $cPid) {
/** @var RequestWrapper $requestWrapper */
$requestWrapper = $arguments['request'];
$queryParams = $requestWrapper->getQueryParams();
$type = 'undefined';
// Load document with current plugin parameters.
$doc = $this->loadDocument($queryParams[$this->prefixId]);
if ($doc === null) {
return $type;
}
$metadata = $doc->getTitledata($cPid);
if (!empty($metadata['type'][0])) {
// Calendar plugin does not support IIIF (yet). Abort for all newspaper related types.
if (
$doc instanceof IiifManifest
&& array_search($metadata['type'][0], ['newspaper', 'ephemera', 'year', 'issue']) !== false
) {
return $type;
}
$type = $metadata['type'][0];
}
return $type;
});
}
/**
* Loads the current document
* @see \Kitodo\Dlf\Common\AbstractPlugin->loadDocument()
*
* @access protected
*
* @param array $piVars The current plugin variables containing a document identifier
*
* @return \Kitodo\Dlf\Common\Document Instance of the current document
*/
protected function loadDocument(array $piVars)
{
// Check for required variable.
if (!empty($piVars['id'])) {
// Get instance of document.
$doc = Document::getInstance($piVars['id']);
if ($doc->ready) {
return $doc;
} else {
Helper::devLog('Failed to load document with UID ' . $piVars['id'], DEVLOG_SEVERITY_WARNING);
}
} elseif (!empty($piVars['recordId'])) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_dlf_documents');
// Get UID of document with given record identifier.
$result = $queryBuilder
->select('tx_dlf_documents.uid AS uid')
->from('tx_dlf_documents')
->where(
$queryBuilder->expr()->eq('tx_dlf_documents.record_id', $queryBuilder->expr()->literal($piVars['recordId'])),
Helper::whereExpression('tx_documents')
)
->setMaxResults(1)
->execute();
if ($resArray = $result->fetch()) {
// Try to load document.
return $this->loadDocument(['id' => $resArray['uid']]);
} else {
Helper::devLog('Failed to load document with record ID "' . $piVars['recordId'] . '"', DEVLOG_SEVERITY_WARNING);
}
}
}
}

View File

@ -0,0 +1,34 @@
<?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\ExpressionLanguage;
use TYPO3\CMS\Core\ExpressionLanguage\AbstractProvider;
use TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\Typo3ConditionFunctionsProvider;
/**
* Wrapper class to provide variables and functions for the ExpressionLanguage.
*
* @author Alexander Bigga <alexander.bigga@slub-dresden.de>
* @package TYPO3
* @subpackage dlf
* @access public
*/
class DocumentTypeProvider extends AbstractProvider
{
public function __construct()
{
$this->expressionLanguageProviders = [
DocumentTypeFunctionProvider::class
];
}
}

View File

@ -0,0 +1,28 @@
<?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.
*/
/*
* Register the DocumentTypeProvider to be used in TypoScript conditions.
*
* Example:
*
* [getDocumentType("{$config.storagePid}") == "newspaper"]
* page.10.variables {
* isNewspaper = TEXT
* isNewspaper.value = newspaper_anchor
* }
* [END]
*/
return [
'typoscript' => [
Kitodo\Dlf\ExpressionLanguage\DocumentTypeProvider::class,
]
];

View File

@ -171,6 +171,43 @@ Basket
Calendar
---------
The calendar plugin may be used with newspaper and ephemeras (periodical
published media). The plugin shows itself an overview of all available
years or all issues in a calendar view of a selected year.
You can't place the plugin together with the pageview plugin on one page.
But you can use TypoScript conditions on this page to select the proper
plugin e.g by setting some specific FLUID variables.
This is an example usage of the TypoScript condition ("getDocumentType")::
[getDocumentType("{$config.storagePid}") == "ephemera"] || [getDocumentType("{$config.storagePid}") == "newspaper"]
page.10.variables {
isNewspaper = TEXT
isNewspaper.value = newspaper_anchor
}
[END]
[getDocumentType("{$config.storagePid}") == "year"]
page.10.variables {
isNewspaper = TEXT
isNewspaper.value = newspaper_year
}
[END]
[getDocumentType("{$config.storagePid}") == "issue"]
page.10.variables {
isNewspaper = TEXT
isNewspaper.value = newspaper_issue
}
[END]
The `{$config.storagePid}` is a TypoScript constant holding the Kitodo.Presentation storage pid.
This way, the FLUID variable "isNewspaper" is set according to the given
value. Inside the FLUID template it's possible to switch to the right plugin
now.
:typoscript:`plugin.tx_dlf_calendar.`
.. t3-field-list-table::
@ -189,6 +226,19 @@ Calendar
:ref:`t3tsref:data-type-page-id`
:Default:
- :Property:
initialDocument
:Data Type:
:ref:`t3tsref:data-type-db`
:Default:
- :Property:
showEmptyMonths
:Data Type:
:ref:`t3tsref:data-type-boolean`
:Default:
1
- :Property:
templateFile_
:Data Type:
@ -196,7 +246,6 @@ Calendar
:Default:
Calendar.tmpl
Collection
----------