【问题标题】:TYPO3 TCA display condition (displayCond) with mysql to MM tableTYPO3 TCA显示条件(displayCond)用mysql转MM表
【发布时间】:2016-12-24 07:23:49
【问题描述】:

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

这个语法可以改正还是不行(这个sn-p不行)

【问题讨论】:

  • IN 需要一个值。也许您尝试使用带有查询语句的用户函数。 docs.typo3.org/typo3cms/TCAReference/Reference/Columns/…
  • @jokumer 这是有用的 1 步,对于初学者还有更多代码/示例吗?我没有看到使用用户函数或用户函数的语法,这不在您提供的参考文献中

标签: mysql typo3 extbase typo3-7.6.x


【解决方案1】:

由于 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',

为符合您需要的扩展名、路径和供应商调整名称。

【讨论】:

  • 那是圣诞礼物!!有美好的日子和新年快乐,看看它是如何完成的是一个巨大的帮助,但不是因为你做了我的工作!
猜你喜欢
  • 2017-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-07
  • 1970-01-01
  • 2016-10-29
相关资源
最近更新 更多