Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/v8compatibility' into de…
Browse files Browse the repository at this point in the history
…velop
  • Loading branch information
Josef Glatz committed Aug 21, 2019
2 parents c7f9bab + b477d12 commit bd595e4
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 12 deletions.
32 changes: 30 additions & 2 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Utility\GeneralUtility;
// @TODO: TYPO3_8-7 support removal: Use statement `TYPO3\CMS\Core\Utility\VersionNumberUtility` can be removed
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
Expand Down Expand Up @@ -36,12 +38,15 @@ protected function findUsers(): QueryResultInterface
}

/**
* @TODO: TYPO3_8-7 support removal: Method userLookupAction(): second parameter can be removed
*
* @param ServerRequestInterface $request
* @param ResponseInterface|null $response
* @return ResponseInterface
* @throws InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidExtensionNameException
*/
public function userLookupAction(ServerRequestInterface $request): ResponseInterface
public function userLookupAction(ServerRequestInterface $request, ResponseInterface $response = null): ResponseInterface
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setLayoutRootPaths([
Expand All @@ -54,7 +59,7 @@ public function userLookupAction(ServerRequestInterface $request): ResponseInter
GeneralUtility::getFileAbsFileName('EXT:beuser_fastswitch/Resources/Private/Partials'),
]);
$view->getRequest()->setControllerExtensionName('BeuserFastswitch');
$view->getRenderingContext()->setControllerName(BackendController::class);
$view->getRenderingContext()->setControllerName(__CLASS__);
$view->getRenderingContext()->setControllerAction('userLookup');

$params = $request->getQueryParams();
Expand All @@ -66,6 +71,29 @@ public function userLookupAction(ServerRequestInterface $request): ResponseInter

$view->assign('users', $userList);

// @TODO: TYPO3_8-7 support removal: Remove conditional switch for response
if ($this->isVersion8() && $response !== null) {
$response->getBody()->write($view->render());
$response = $response->withHeader('Content-Type', 'text/html; charset=utf-8');

return $response;
}

return new HtmlResponse($view->render());
}

/**
* Check if current TYPO3 version matches 8.7
* @TODO: TYPO3_8-7 support removal: Method can be removed
*
* @return bool
*/
protected function isVersion8(): bool
{
$constraintVersionMax = 8999999;
$constraintVersionMin = 8000000;

return VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) < $constraintVersionMax
&& VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) > $constraintVersionMin;
}
}
41 changes: 41 additions & 0 deletions Classes/ViewHelpers/Condition/IsCoreVersion8ViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types = 1);

namespace JosefGlatz\BeuserFastswitch\ViewHelpers\Condition;

use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;

/**
* Class IsCoreVersionViewHelper
*
* @TODO: TYPO3_8-7 support removal: ViewHelper can be removed
*/
class IsCoreVersion8ViewHelper extends AbstractConditionViewHelper
{
/**
* Main method of this ViewHelper to check if current TYPO3 version matches 8.7
*
* @param null $arguments
* @return bool
*/
protected static function evaluateCondition($arguments = null): bool
{
$constraintVersionMax = 8999999;
$constraintVersionMin = 8000000;

return VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) < $constraintVersionMax
&& VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) > $constraintVersionMin;
}

/**
* @return mixed
*/
public function render()
{
if (static::evaluateCondition($this->arguments)) {
return $this->renderThenChild();
}
return $this->renderElseChild();
}
}
29 changes: 26 additions & 3 deletions Classes/ViewHelpers/SwitchUserViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
// @TODO: TYPO3_8-7 support removal: Use statement `TYPO3\CMS\Core\Utility\VersionNumberUtility` can be removed
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
Expand Down Expand Up @@ -49,7 +51,7 @@ public function initializeArguments()
* @return string
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
{
$backendUser = $arguments['backendUser'];
$class = $arguments['class'];
Expand All @@ -60,9 +62,30 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
}
$title = LocalizationUtility::translate('toolbar.beuser.fastswitch.dropdown.user.btn.switch', 'beuser_fastswitch');

// @TODO: TYPO3_8-7 support removal: buildUriFromModule condition (`$href` can be directly set within the return statement)
if (static::isVersion8()) {
$href = $uriBuilder->buildUriFromModule('system_BeuserTxBeuser', ['SwitchUser' => $backendUser->getUid()]);
} else {
$href = $uriBuilder->buildUriFromRoute('system_BeuserTxBeuser', ['SwitchUser' => $backendUser->getUid()]);
}

return '<a class="' . htmlspecialchars($class) . '" href="' .
htmlspecialchars($uriBuilder->buildUriFromRoute('system_BeuserTxBeuser', ['SwitchUser' => $backendUser->getUid()])) .
'" target="_top" title="' . htmlspecialchars($title) . '">' .
htmlspecialchars($href) . '" target="_top" title="' . htmlspecialchars($title) . '">' .
$iconFactory->getIcon('actions-system-backend-user-switch', Icon::SIZE_SMALL)->render('inline') . '</a>';
}

/**
* Check if current TYPO3 version matches 8.7
* @TODO: TYPO3_8-7 support removal: Method can be removed
*
* @return bool
*/
protected static function isVersion8(): bool
{
$constraintVersionMax = 8999999;
$constraintVersionMin = 8000000;

return VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) < $constraintVersionMax
&& VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version) > $constraintVersionMin;
}
}
47 changes: 47 additions & 0 deletions Resources/Private/Partials/TYPO3_8-7/UserList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<html xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
xmlns:bu="http://typo3.org/ns/TYPO3/CMS/Beuser/ViewHelpers"
xmlns:buf="http://typo3.org/ns/JosefGlatz/BeuserFastswitch/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:comment><!-- @TODO: TYPO3_8-7 support removal: Fluid partial can be completely dropped --></f:comment>
<f:if condition="{users}">
<f:then>
<f:for each="{users}" as="user">
<div class="beuser-fastswitch__useritem">
<div class="beuser-fastswitch__useritem-icon">
<a href="#"
class="t3js-contextmenutrigger"
data-table="be_users"
data-uid="{user.uid}"
title="Open contextmenu for user id={user.uid}">
<be:avatar backendUser="{user.uid}" showIcon="TRUE"/>
</a>
</div>
<a class="beuser-fastswitch__useritem-title"
href="{bu:editRecord(parameters: 'edit[be_users][{user.1.uid}]=edit&returnUrl={returnUrl}')}"
target="_new"
title="{f:translate(key: 'toolbar.beuser.fastswitch.dropdown.user.userNameTitle', arguments: {0:user.username})}{f:if(condition: '{user.description}', then: ' ({user.description})')}">
<div class="dropdown-table-title-ellipsis">{user.realName}</div>
<span class="text-muted dropdown-table-title-ellipsis">{user.username}</span>
</a>
<div class="beuser-fastswitch__useritem-actions">
<f:render section="Info" arguments="{user: user}"/>
<f:render section="Switch" arguments="{user: user}"/>
</div>
</div>
</f:for>
</f:then>
</f:if>

<f:section name="Info">
<a class="dropdown-table-actions-btn dropdown-table-actions-btn-edit" href="#"
onclick="top.launchView('be_users', '{user.uid}'); return false;"
title="{f:translate(key: 'toolbar.beuser.fastswitch.dropdown.user.btn.info', arguments: {0:user.username})}">
<core:icon identifier="actions-document-info" alternativeMarkupIdentifier="inline"/>
</a>
</f:section>

<f:section name="Switch">
<buf:switchUser backendUser="{user}" class="dropdown-table-actions-btn dropdown-table-actions-btn-delete"/>
</f:section>
</html>
1 change: 0 additions & 1 deletion Resources/Private/Partials/UserList.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<html xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
xmlns:bu="http://typo3.org/ns/TYPO3/CMS/Beuser/ViewHelpers"
xmlns:buf="http://typo3.org/ns/JosefGlatz/BeuserFastswitch/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:if condition="{users}">
Expand Down
12 changes: 9 additions & 3 deletions Resources/Private/Templates/DropDown.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<html xmlns:core="http://typo3.org/ns/TYPO3/CMS/Core/ViewHelpers"
xmlns:be="http://typo3.org/ns/TYPO3/CMS/Backend/ViewHelpers"
xmlns:bu="http://typo3.org/ns/TYPO3/CMS/Beuser/ViewHelpers"
xmlns:buf="http://typo3.org/ns/JosefGlatz/BeuserFastswitch/ViewHelpers"
data-namespace-typo3-fluid="true">

Expand Down Expand Up @@ -30,7 +28,15 @@ <h3 class="dropdown-headline">
</form>
<div id="beuser-fastswitch-ajax-result">
<f:if condition="{users}">
<f:render partial="UserList" arguments="{users: users}"/>
<f:comment><!-- @TODO: TYPO3_8-7 support removal: Fluid condition can be removed --></f:comment>
<buf:condition.isCoreVersion8>
<f:then>
<f:render partial="TYPO3_8-7/UserList" arguments="{users: users}"/>
</f:then>
<f:else>
<f:render partial="UserList" arguments="{users: users}"/>
</f:else>
</buf:condition.isCoreVersion8>
</f:if>
</div>
</f:then>
Expand Down
13 changes: 12 additions & 1 deletion Resources/Private/Templates/UserLookup.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<html xmlns:buf="http://typo3.org/ns/JosefGlatz/BeuserFastswitch/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:if condition="{users}">
<f:then>
<f:render partial="UserList" arguments="{users: users}"/>
<f:comment><!-- @TODO: TYPO3_8-7 support removal: Fluid condition can be removed --></f:comment>
<buf:condition.isCoreVersion8>
<f:then>
<f:render partial="TYPO3_8-7/UserList" arguments="{users: users}"/>
</f:then>
<f:else>
<f:render partial="UserList" arguments="{users: users}"/>
</f:else>
</buf:condition.isCoreVersion8>
</f:then>
<f:else>
<p>
{f:translate(key: 'toolbar.beuser.fastswitch.dropdown.noUsers')}
</p>
</f:else>
</f:if>
</html>
4 changes: 4 additions & 0 deletions Resources/Public/Css/beuser_fastswitch.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@
display: flex;
align-items: center;
}
.beuser-fastswitch__useritem-actions .btn.disabled {
opacity: 0 !important;
width: 24px !important;
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"homepage": "http://josefglatz.at",
"license": "GPL-3.0",
"require": {
"typo3/cms-core": "^9.5"
"typo3/cms-core": "^8.7 || ^9.5",
"php": ">=7.2"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[
'depends' =>
[
'typo3' => '9.5.0-9.5.99',
'typo3' => '8.7.0-9.5.99',
],
'conflicts' =>
[
Expand Down

0 comments on commit bd595e4

Please sign in to comment.