TYPO3 7.6.10:如何扩展felogin扩展? [英] TYPO3 7.6.10: How to extend the felogin extension?

查看:55
本文介绍了TYPO3 7.6.10:如何扩展felogin扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用名为"feloginextended"的额外扩展来扩展核心扩展 felogin .

I tried to extend the core extension felogin with an extra extension called "feloginextended".

我想将当前用户的 first_name last_name 属性添加到我的注销公式中.

I want to add the first_name and the last_name property of the current user into my logout formular.

这是我的覆盖的模板(仅退出部分):

This is my overridden template (only the logout part):

<!--###TEMPLATE_LOGOUT###-->
<form class="login-form" action="###ACTION_URI###" target="_top" method="post">
    <div>
        <div class="user">###FIRSTNAME### ###LASTNAME###</div>
        <a class="page-link-button" href="http://tf.lightblue.eu/index.php?id=14">Meine Siegel</a>
        <a class="page-link-button" href="http://tf.lightblue.eu/index.php?id=15">Mein Account</a>
        <input class="form-btn" type="submit" name="submit" value="Logout" />
     </div>

    <div class="felogin-hidden">
        <input type="hidden" name="logintype" value="logout" />
        <input type="hidden" name="pid" value="###STORAGE_PID###" />
        <input type="hidden" name="###PREFIXID###[noredirect]" value="###NOREDIRECT###" />
    </div>
</form>
<!--###TEMPLATE_LOGOUT###-->

然后我将控制器 Classes\Xclass\FrontendLoginController 添加到了我的扩展程序中.

Then I added the Controller Classes\Xclass\FrontendLoginController to my extension.

我复制了原始文件,并在showLogout函数中添加了一些更改以设置标记:

I copied the original file and add some changes in the showLogout function, to set the markers:

 <?php
 namespace Typo3\feloginextended\Xclass;

 use \TYPO3\CMS\Frontend\Plugin\AbstractPlugin;

 /**
  * Plugin 'Website User Login' for the 'felogin' extension.
  */
 class FrontendLoginController extends AbstractPlugin
 {

 /**
 * Shows logout form
 *
 * @return string The content.
 */
protected function showLogout()
{
    $subpart = $this->cObj->getSubpart($this->template, '###TEMPLATE_LOGOUT###');
    $subpartArray = ($linkpartArray = array());
    $markerArray['###STATUS_HEADER###'] = $this->getDisplayText('status_header', $this->conf['logoutHeader_stdWrap.']);
    $markerArray['###STATUS_MESSAGE###'] = $this->getDisplayText('status_message', $this->conf['logoutMessage_stdWrap.']);
    $this->cObj->stdWrap($this->flexFormValue('message', 's_status'), $this->conf['logoutMessage_stdWrap.']);
    $markerArray['###LEGEND###'] = $this->pi_getLL('logout', '', true);
    $markerArray['###ACTION_URI###'] = $this->getPageLink('', array(), true);
    $markerArray['###LOGOUT_LABEL###'] = $this->pi_getLL('logout', '', true);
    $markerArray['###NAME###'] = htmlspecialchars($this->frontendController->fe_user->user['name']);
    $markerArray['###STORAGE_PID###'] = $this->spid;
    $markerArray['###USERNAME###'] = htmlspecialchars($this->frontendController->fe_user->user['username']);
    $markerArray['###USERNAME_LABEL###'] = $this->pi_getLL('username', '', true);
    $markerArray['###NOREDIRECT###'] = $this->noRedirect ? '1' : '0';
    $markerArray['###PREFIXID###'] = $this->prefixId;
    // my custom changes-----------------------------------
    $markerArray['###FIRSTNAME###'] = htmlspecialchars($this->frontendController->fe_user->user['first_name']);
    $markerArray['###LASTNAME###'] = htmlspecialchars($this->frontendController->fe_user->user['last_name']);
    //------------------------------------------------------
    $markerArray = array_merge($markerArray, $this->getUserFieldMarkers());
    if ($this->redirectUrl) {
        // Use redirectUrl for action tag because of possible access restricted pages
        $markerArray['###ACTION_URI###'] = htmlspecialchars($this->redirectUrl);
        $this->redirectUrl = '';
    }
    return $this->cObj->substituteMarkerArrayCached($subpart, $markerArray, $subpartArray, $linkpartArray);
}
}

然后,我将模板注册到 ext_typoscript_setup.txt 文件中:

Then I register my template in the ext_typoscript_setup.txt file:

plugin.tx_felogin_pi1 {
    templateFile = EXT:feloginextended/Resources/Private/Templates/FrontendLogin.html
}

最后一步是在 ext_localconf.php 中注册控制器:

And my final step was the registration of the controller in the ext_localconf.php:

<?php
if (!defined('TYPO3_MODE')) {
    die('Access denied.');
}

$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Felogin\\Controller\\FrontendLoginController'] = array(
    'className' => 'Typo3\\Feloginextended\\Xclass\\FrontendLoginController',
);
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['tx_felogin_pi1'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Felogin\\Controller\\FrontendLoginController'];

如果将此更改添加到felogin扩展名的原始文件中,那么我有解决方案.

If add this changes into the original files of the felogin extension, then I have a solution.

但是这种方式很脏,将来我无法轻易更新felogin扩展名.

But this way is very dirty and in the future I can't update the felogin extension easily.

我找到了这个解决方案": https://forum.typo3.org/index.php/t/202500/ 但这对我不起作用.

I found this "solution": https://forum.typo3.org/index.php/t/202500/ But it don't work for me.

有任何想法或其他方式将当前用户的名字和姓氏带出注销公式吗?

Have anyone an idea or have an other way to bring the first and the last name of the current user to the logout formular?

我每次都会收到http错误500!

I get everytime a http error 500!

感谢费利克斯

推荐答案

解决方案非常简单.您只需将标记###FEUSER_FIRST_NAME######FEUSER_LAST_NAME###添加到模板中,它们就会被正确的值替换.此模式是常规模式,可以在用户的​​所有字段上使用:

The solution is pretty simple. You can just add the markers ###FEUSER_FIRST_NAME### and ###FEUSER_LAST_NAME### to your template and they will be replaced by the right values. This schema is general and can be used on all fields of the user:

###FEUSER_{DB field in uppercase}###.请注意,这些字段使用下划线而不是小写的驼峰大写字母.

###FEUSER_{DB field in uppercase}###. Note that the fields are used with underscores and not the lower camelcase.

这在TYPO3 6.x中有效,并且代码在7.6中看起来相同,因此也应该起作用.

This works in TYPO3 6.x and the code looks the same in 7.6 so it should work too.

这篇关于TYPO3 7.6.10:如何扩展felogin扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆