【问题标题】:TYPO3 - Custom extension : show in flexformTYPO3 - 自定义扩展:以 flexform 显示
【发布时间】:2017-12-29 11:09:02
【问题描述】:

我在 TYPO3 6.2 上使用 Extension Builder 制作了自己的扩展,目标是让后端用户创建我们公司的事件(包括名称、位置、日期、人数等...)。

  • 我创建了一个后端插件,效果很好。
  • 我创建了一个前端插件,但是我不知道如何编写我的 flexform 文件以便让后端用户选择要显示的事件(我猜是通过“显示”操作) ... 最好的结果是获得包含所有现有事件的选择列表。

怎么做?

在我的 ext_localconf.php 中,我有:

<?php

    \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
        'Mycompany.' . $_EXTKEY,
        'Displayevent',
        array(
            'Event' => 'show',
            
        ),
        // non-cacheable actions
        array(
            'Event' => 'show',
            
        )
    );
    
?>

但在前端有一个 Typo3 错误:

1298012500:未为 Mycompany\MycompanyEvents\Controller\EventController->show 设置必需的参数“event”

这里是我的 showAction() 代码:

/**
 * action show
 *
 * @param \MyCompany\mycompany_events\Domain\Model\Event $event
 * @return void
 */
public function showAction(\MyCompany\mycompany_events\Domain\Model\Event $event) {
    $this->view->assign('event', $event);
}

【问题讨论】:

    标签: typo3 typo3-6.2.x typo3-extensions


    【解决方案1】:

    尝试按照以下步骤调用 flexform。

    在您的 ext_tables.php 文件中添加以下代码。

    //extenstion name
    $extensionName = \TYPO3\CMS\Core\Utility\GeneralUtility::underscoredToUpperCamelCase($_EXTKEY);
    
    //plugin integration
    $frontendpluginName = 'your_plugin_name';
    $pluginSignature = strtolower($extensionName) . '_'.strtolower(
        $frontendpluginName
    );
    
    $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist'][$pluginSignature] = 'pi_flexform';
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
        $pluginSignature,
        'FILE:EXT:' . $_EXTKEY . '/Configuration/FlexForms/configure_plugin.xml'
    );
    

    现在,在此目录/Configuration/FlexForms/ 中创建 flexform 文件,如下所示,并将 userFunct 用于事件选择列表。

    <T3DataStructure>
        <sheets>
            <!--
                ################################
                  SHEET General Settings
                ################################
            -->
            <sDEF>
                <ROOT>
                    <TCEforms>
                        <sheetTitle>General</sheetTitle>
                    </TCEforms>
                    <type>array</type>
                    <el>
                        <settings.variable_name>
                          <TCEforms>
                            <label>Title</label>
                            <config>
                                <type>select</type>
                                <itemsProcFunc>EXT:ext_key/Classes/Utility/class.tx_event_utility.php:tx_event_utility->getEventList</itemsProcFunc>
                                <multiple>0</multiple>
                                <minitems>0</minitems>
                                <maxitems>50</maxitems>
                                <size>5</size>
                            </config>
                          </TCEforms>
                        </settings.variable_name>
                    </el>               
                </ROOT>
            </sDEF>
        </sheets>
    </T3DataStructure>
    

    现在,在此路径 /ext_key/Classes/Utility/ 上创建 tx_event_utility.php 文件,如下所示。

    <?php
    class tx_event_utility {
    
        protected $objectManager;
        protected $configurationManager;
        protected $pluginSetting;
        protected $objectCategoryRepository;
    
        function __construct() {
            $this->objectManager = TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
            $this->configurationManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
            $this->pluginSetting = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
            $this->objectCategoryRepository = $this->objectManager->get('added repositry namespace');
       }
    
       function getEventList($config, $item) {
    
                // write code for geting event list
            }
            return $config;
        }
    
    }
    ?>
    

    【讨论】:

    • 谢谢!现在后端用户得到一个包含所有事件的 flexform 列表。但是错误仍然存​​在(Typo3 不明白它必须使用来自 flexform 的值?)
    • 和开头一样 -> Mycompany\MycompanyEvents\Controller\EventController->show 没有设置必填参数“event”
    • 请在 controller.php 文件中更新您的 showAction() 代码。所以我可以检查并提供建议。
    • 感谢您的帮助;完成。我不明白 TYPO3 怎么知道要在 showAction() 中显示的 $event 是来自插件的事件...顺便说一下,我的控制器和树枝视图是由扩展生成器生成的;​​)
    • 不,我仍然有错误。所做的是让用户在后端选择要显示的事件,但在前端它不显示
    【解决方案2】:

    添加文件Yourext/Configuration/TCA/Overrides/tt_content.php

    <?php
    defined('TYPO3_MODE') or die();
    
    // register plugin and flexform
    \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
            'yourext',
            'Name',
            'LLL:EXT: yourext/Resources/Private/Language/locallang_be.xlf:name_plugin'
    );
    $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_excludelist']['yourext_name'] = 'select_key';
    $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['yourext_name'] = 'pi_flexform';
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue(
            'yourext_name',
            'FILE:EXT:yourext/Configuration/FlexForms/flexform.xml'
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多