我创建了一个自定义TYPO3条件here。
如果我以这种方式使用条件:
## Custom JavaScript Includes for LogoClaim Backendlayout
[RM\RmBase\TypoScript\BackendlayoutCondition = pagets__pagelayout_logoclaim_portal] || [RM\RmBase\TypoScript\BackendlayoutCondition = pagets__pagelayout_logoclaim_subpage]
page.includeJSFooter.belayoutJavascript = EXT:rm_base/Resources/Public/JS/be_logoclaim.js
[global]
## Custom JavaScript Includes for LogoFull Backendlayout
[RM\RmBase\TypoScript\BackendlayoutCondition = pagets__pagelayout_logofull_portal] || [RM\RmBase\TypoScript\BackendlayoutCondition = pagets__pagelayout_logofull_subpage]
page.includeJSFooter.belayoutJavascript = EXT:rm_base/Resources/Public/JS/be_logofull.js
[global]
我从\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($conditionParameters,'cond Params');
得到8个调试。
如果我单独使用它:
## Custom JavaScript Includes for LogoClaim Backendlayout
[RM\RmBase\TypoScript\BackendlayoutCondition = pagets__pagelayout_logoclaim_portal]
page.includeJSFooter.belayoutJavascript = EXT:rm_base/Resources/Public/JS/be_logoclaim.js
[global]
[RM\RmBase\TypoScript\BackendlayoutCondition = pagets__pagelayout_logoclaim_subpage]
page.includeJSFooter.belayoutJavascript = EXT:rm_base/Resources/Public/JS/be_logoclaim.js
[global]
## Custom JavaScript Includes for LogoFull Backendlayout
[RM\RmBase\TypoScript\BackendlayoutCondition = pagets__pagelayout_logofull_portal]
page.includeJSFooter.belayoutJavascript = EXT:rm_base/Resources/Public/JS/be_logofull.js
[global]
[RM\RmBase\TypoScript\BackendlayoutCondition = pagets__pagelayout_logofull_subpage]
page.includeJSFooter.belayoutJavascript = EXT:rm_base/Resources/Public/JS/be_logofull.js
[global]
我接受了四次调试。
Logical条件在OR-Variant中调用8次,在Single-Call-Variant中调用4次。
我的想法是冗余代码少,但它看起来像是一个双重检查条件。那么基于性能,我最好使用单呼叫条件?
这个或那个PRO的PRO和CON是什么?
修改
我的条件代码:
<?php
namespace RM\RmBase\TypoScript;
use \TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractCondition;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;;
class BackendlayoutCondition extends AbstractCondition
{
/**
* Evaluate condition
*
* @param array $conditionParameters
* @return bool
*/
public function matchCondition(array $conditionParameters)
{
# Return false if in Backend (Condition for Frontend only)
if (!$GLOBALS['TSFE']) return false;
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($conditionParameters,'cond Params');
# QueryBuilder for Table: pages
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
# Check if current BackendLayout is inside the $conditionParameters
if (!empty($conditionParameters) && substr($conditionParameters[0], 0, 1) === '=') {
# Trim the Parameter to get the correct Value of the Parameter (behind '=')
$conditionParameters[0] = trim(substr($conditionParameters[0], 1));
# Get Backendlayout on this Page
$backendLayoutOnThisPage = $queryBuilder
->select('backend_layout')
->from('pages')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(intval($GLOBALS['TSFE']->id), \PDO::PARAM_INT))
)
->execute();
# Store Backendlayout Value of the current Page in $backendLayoutOnThisPage
$backendLayoutOnThisPage = $backendLayoutOnThisPage->fetch()['backend_layout'];
} else {
# If no ConditionParameter was set return false
return false;
}
# Check if parent BackendLayout_NextLevel is inside the $conditionParameters
if ($backendLayoutOnThisPage == '') {
# Get pageRepository
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$pageRepository = $objectManager->get('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
# Get Rootline of the current Page
$pageRootline = $pageRepository->getRootLine(intval($GLOBALS['TSFE']->id));
# Set rootlineIndex to the Parent Page Index
$rootlineIndex = count($pageRootline)-2;
# Check Parent Page Backendlayout_NextLevel till 0 or Backendlayout found
while ($rootlineIndex > 0) {
if ($pageRootline[$rootlineIndex]['backend_layout_next_level'] == $conditionParameters[0]) {
return true;
} else {
$rootlineIndex--;
}
}
# No BackendLayout_NextLevel found till 0
return false;
} else {
# If Condition Backendlayout found return true, otherwise return false
if ($backendLayoutOnThisPage == $conditionParameters[0]) {
return true;
} else {
return false;
}
}
}
}