代码之家  ›  专栏  ›  技术社区  ›  webman

类型3:TCA显示条件(displayCond)与mysql到MM表

  •  1
  • webman  · 技术社区  · 9 年前

    我有一个扩展,主表带有一个复选框,如果项目已经通过MM表(相对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
      ]
    ],
    

    这个语法可以纠正吗?还是不可能(这个代码段不起作用)

    1 回复  |  直到 9 年前
        1
  •  8
  •   jokumer    9 年前

    因为TYPO3 7.6 userFunc可用作显示条件。

    在您的情况下,我建议您的TCA配置:

    'checkbox' => [
        'displayCond' =>'USER:VendorName\\Myext\\DisplayConditionMatcher->displayIfTxMyextObjectHasNoMMRelation',
        'exclude' => 1,
        'label' => 'Checkbox',
        'config' => [
            'type' => 'check',
            'default' => 0
        ]
    ],
    

    以及一个名为DisplayConditionMatcher的PHP类。php位于扩展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类中已经实现的否定:

    'displayCond' =>'USER:VendorName\\Myext\\DisplayConditionMatcher->displayIfTxMyextObjectHasNoMMRelation:negate',
    

    根据您的需要调整扩展名、路径和供应商的名称。

    推荐文章