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
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.
Assumed that your extension
EXT:feloginextended
is installed and you cleared all caches including the full cache clear provided by the install tool, you have done everything correct. Delete also the directory/typo3temp/autoload
completely.The only thing which may be wrong is the loading order of the extensions, which is important in case you define your TS-Setup inside the file
ext_typoscript_setup.txt
. In this case you must force your extension to be loaded after the original EXT:felogin extension. And the only way to assure that is to add the extension felogin to the list of "suggests" constraint setting insideEXT:feloginextended/ext_emconf.php
. Then you must fully deinstall your extension and install it again.To continue the answer after your error 500 information. This must be a class loader problem as well, the fact that you are seeing 500 error is caused by PHP or TYPO3 error reporting configuration.
Anyway I copied your approach as follows:
EXT:my_extension/ext_localconf.php
EXT:my_extension/ext_typoscript_setup.txt
EXT:my_extension/Classes/FrontendLoginController.php
EXT:my_extension/FrontendLogin.html
The result is totally correct instead of the login form I see 'My New Login', so everything is working for me.
The solution for you is:
1) You have a typo in the namespace. It must be
namespace Typo3\**F**eloginextended\Xclass;
instead ofnamespace Typo3\**f**eloginextended\Xclass;
2) You must inherit from
TYPO3\CMS\Felogin\Controller\FrontendLoginController
Do not forget to clear typo3temp/Cache/* and typo3temp/autoload/* !