drfqfuhej48511519 2016-10-26 10:34
浏览 31
已采纳

TYPO3 7.6.10:如何扩展felogin扩展?

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

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###-->

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

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);
}
}

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

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

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'];

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

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

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?

EDIT: I get everytime a http error 500!

Thanks Felix

  • 写回答

2条回答 默认 最新

  • doucan8521 2016-10-27 20:32
    关注

    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}###. Note that the fields are used with underscores and not the lower camelcase.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路