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条)

报告相同问题?

悬赏问题

  • ¥15 ios可以实现ymodem-1k协议 1024字节传输吗?
  • ¥300 寻抓云闪付tn组成网页付款链接
  • ¥15 请问Ubuntu要怎么安装chrome呀?
  • ¥15 视频编码 十六进制问题
  • ¥15 Xsheii7我安装这个文件的时候跳出来另一个文件已锁定文件的无一部分进程无法访问。这个该怎么解决
  • ¥15 unity terrain打包后地形错位,跟建筑不在同一个位置,怎么办
  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)