TYPO3 TCA显示条件(displayCond) with mysql to MM table
TYPO3 TCA display condition (displayCond) with mysql to MM table
我有一个带有主要 table 的扩展,带有一个复选框,如果该项目已经通过 MM table 建立关系,则该复选框不可用,相关 TCA :
'checkbox' => [
'displayCond' =>'FIELD:uid:!IN:SELECT uid_foreign FROM tx_myext_object_object_mm',
'exclude' => 0,
'label' => 'checkbox',
'config' => [
'type' => 'check',
'items' => [
'1' => [
'0' => 'LLL:EXT:lang/locallang_core.xlf:labels.enabled'
]
],
'default' => 0
]
],
可以更正此语法还是不可能(此代码段不起作用)
由于 TYPO3 7.6 userFunc 可用作显示条件。
对于你的情况,我建议你的 TCA 配置:
'checkbox' => [
'displayCond' =>'USER:VendorName\Myext\DisplayConditionMatcher->displayIfTxMyextObjectHasNoMMRelation',
'exclude' => 1,
'label' => 'Checkbox',
'config' => [
'type' => 'check',
'default' => 0
]
],
还有一个名为 DisplayConditionMatcher.php 的 PHP class 位于您的分机 EXT:myext/Classes/ 中,内容如下:
<?php
namespace VendorName\Myext;
/**
* Class DisplayConditionMatcher
*
* @package TYPO3
* @subpackage tx_myext
* @author 2016 J.Kummer <typo3 et enobe dot de>
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class DisplayConditionMatcher {
/**
* Checks for already existing mm relation of tx_myext_object
* Returns true, if no mm relation found
*
* @param array $configuration
* @param \TYPO3\CMS\Backend\Form\FormDataProvider\EvaluateDisplayConditions $evaluateDisplayConditions
* @return bool
*/
public function displayIfTxMyextObjectHasNoMMRelation(array $configuration, $evaluateDisplayConditions = null)
{
$result = true;
if (isset($configuration['record']['uid'])) {
$countRows = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
'uid_foreign',
'tx_myext_object_object_mm',
'uid_foreign = ' . intval($configuration['record']['uid'])
);
if ($countRows > 0) {
$result = false;
}
}
if (isset($configuration['conditionParameters'][0]) && $configuration['conditionParameters'][0] === 'negate') {
$result = !$result;
}
return $result;
}
}
您可以为 userFunc 类型的 displayCondition 传递以冒号分隔的附加参数,如 TYPO3 CMS TCA 参考中所述。例如否定,已经在 PHP class:
中实现
'displayCond' =>'USER:VendorName\Myext\DisplayConditionMatcher->displayIfTxMyextObjectHasNoMMRelation:negate',
根据您的需要调整扩展名、路径和供应商的名称。
我有一个带有主要 table 的扩展,带有一个复选框,如果该项目已经通过 MM table 建立关系,则该复选框不可用,相关 TCA :
'checkbox' => [
'displayCond' =>'FIELD:uid:!IN:SELECT uid_foreign FROM tx_myext_object_object_mm',
'exclude' => 0,
'label' => 'checkbox',
'config' => [
'type' => 'check',
'items' => [
'1' => [
'0' => 'LLL:EXT:lang/locallang_core.xlf:labels.enabled'
]
],
'default' => 0
]
],
可以更正此语法还是不可能(此代码段不起作用)
由于 TYPO3 7.6 userFunc 可用作显示条件。
对于你的情况,我建议你的 TCA 配置:
'checkbox' => [
'displayCond' =>'USER:VendorName\Myext\DisplayConditionMatcher->displayIfTxMyextObjectHasNoMMRelation',
'exclude' => 1,
'label' => 'Checkbox',
'config' => [
'type' => 'check',
'default' => 0
]
],
还有一个名为 DisplayConditionMatcher.php 的 PHP class 位于您的分机 EXT:myext/Classes/ 中,内容如下:
<?php
namespace VendorName\Myext;
/**
* Class DisplayConditionMatcher
*
* @package TYPO3
* @subpackage tx_myext
* @author 2016 J.Kummer <typo3 et enobe dot de>
* @copyright Copyright belongs to the respective authors
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class DisplayConditionMatcher {
/**
* Checks for already existing mm relation of tx_myext_object
* Returns true, if no mm relation found
*
* @param array $configuration
* @param \TYPO3\CMS\Backend\Form\FormDataProvider\EvaluateDisplayConditions $evaluateDisplayConditions
* @return bool
*/
public function displayIfTxMyextObjectHasNoMMRelation(array $configuration, $evaluateDisplayConditions = null)
{
$result = true;
if (isset($configuration['record']['uid'])) {
$countRows = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
'uid_foreign',
'tx_myext_object_object_mm',
'uid_foreign = ' . intval($configuration['record']['uid'])
);
if ($countRows > 0) {
$result = false;
}
}
if (isset($configuration['conditionParameters'][0]) && $configuration['conditionParameters'][0] === 'negate') {
$result = !$result;
}
return $result;
}
}
您可以为 userFunc 类型的 displayCondition 传递以冒号分隔的附加参数,如 TYPO3 CMS TCA 参考中所述。例如否定,已经在 PHP class:
中实现'displayCond' =>'USER:VendorName\Myext\DisplayConditionMatcher->displayIfTxMyextObjectHasNoMMRelation:negate',
根据您的需要调整扩展名、路径和供应商的名称。