first commit
This commit is contained in:
commit
1218dd1517
12716 files changed
+989233
No files matched your search
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Beuser\Exception;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Get a value from an array by given key.
|
||||
* @internal
|
||||
*/
|
||||
class ArrayElementViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('array', 'array', 'Array to search in', true);
|
||||
$this->registerArgument('key', 'string', 'Key to return its value', true);
|
||||
$this->registerArgument('subKey', 'string', 'If result of key access is an array, subkey can be used to fetch an element from this again', false, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array element by key. Accessed values must be scalar (string, int, float or double)
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @throws Exception
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$array = $arguments['array'];
|
||||
$key = $arguments['key'];
|
||||
$subKey = $arguments['subKey'];
|
||||
$result = '';
|
||||
if (is_array($array) && isset($array[$key])) {
|
||||
$result = $array[$key];
|
||||
if (is_array($result) && $subKey && isset($result[$subKey])) {
|
||||
$result = $result[$subKey];
|
||||
}
|
||||
}
|
||||
if (!is_scalar($result)) {
|
||||
throw new Exception('Only scalar return values (string, int, float or double) are supported.', 1382284105);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers\Display;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Converts comma separated list of pages uids to html unordered list (<ul>) with speaking titles
|
||||
* @internal
|
||||
*/
|
||||
class PagesViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('uids', 'string', '', false, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render unordered list for pages
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$uids = $arguments['uids'];
|
||||
if (!$uids) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$content = '';
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
|
||||
$queryBuilder->getRestrictions()->removeAll();
|
||||
|
||||
$res = $queryBuilder
|
||||
->select('uid', 'title')
|
||||
->from('pages')
|
||||
->where(
|
||||
$queryBuilder->expr()->in(
|
||||
'uid',
|
||||
$queryBuilder->createNamedParameter(
|
||||
GeneralUtility::intExplode(',', $uids),
|
||||
Connection::PARAM_INT_ARRAY
|
||||
)
|
||||
)
|
||||
)
|
||||
->orderBy('uid', 'ASC')
|
||||
->execute();
|
||||
|
||||
while ($row = $res->fetch()) {
|
||||
$content .= '<li>' . htmlspecialchars($row['title']) . ' [' . htmlspecialchars($row['uid']) . ']</li>';
|
||||
}
|
||||
return '<ul>' . $content . '</ul>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers\Display;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Converts comma separated list of sys_filemounts uids to html unordered list (<ul>) with speaking titles
|
||||
* @internal
|
||||
*/
|
||||
class SysFileMountsViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('uids', 'string', '', false, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render unordered list for sys_filemounts
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$uids = $arguments['uids'];
|
||||
if (!$uids) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$content = '';
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_filemounts');
|
||||
$queryBuilder->getRestrictions()->removeAll();
|
||||
|
||||
$res = $queryBuilder
|
||||
->select('uid', 'title')
|
||||
->from('sys_filemounts')
|
||||
->where(
|
||||
$queryBuilder->expr()->in(
|
||||
'uid',
|
||||
$queryBuilder->createNamedParameter(
|
||||
GeneralUtility::intExplode(',', $uids),
|
||||
Connection::PARAM_INT_ARRAY
|
||||
)
|
||||
)
|
||||
)
|
||||
->orderBy('title', 'ASC')
|
||||
->execute();
|
||||
|
||||
while ($row = $res->fetch()) {
|
||||
$content .= '<li>' . htmlspecialchars($row['title']) . ' [' . htmlspecialchars($row['uid']) . ']</li>';
|
||||
}
|
||||
return '<ul>' . $content . '</ul>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers\Display;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Database\Connection;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Converts comma separated list of sys_language uids to html unordered list (<ul>) with speaking titles
|
||||
* @internal
|
||||
*/
|
||||
class SysLanguageViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('uids', 'string', '', false, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render unordered list for sys_language
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$uids = $arguments['uids'];
|
||||
if (!$uids) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$content = '';
|
||||
|
||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
|
||||
$queryBuilder->getRestrictions()->removeAll();
|
||||
|
||||
$res = $queryBuilder
|
||||
->select('uid', 'title', 'flag')
|
||||
->from('sys_language')
|
||||
->where(
|
||||
$queryBuilder->expr()->in(
|
||||
'uid',
|
||||
$queryBuilder->createNamedParameter(
|
||||
GeneralUtility::intExplode(',', $uids),
|
||||
Connection::PARAM_INT_ARRAY
|
||||
)
|
||||
)
|
||||
)
|
||||
->orderBy('sorting')
|
||||
->execute();
|
||||
|
||||
while ($row = $res->fetch()) {
|
||||
$content .= '<li>' . htmlspecialchars($row['title']) . ' [' . htmlspecialchars($row['uid']) . ']</li>';
|
||||
}
|
||||
return '<ul>' . $content . '</ul>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Render a link to DataHandler command
|
||||
* @internal
|
||||
*/
|
||||
class IssueCommandViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('parameters', 'string', 'Is a set of GET params to send to route tce_db (SimpleDataHandlerController). Example: "&cmd[tt_content][123][move]=456" or "&data[tt_content][123][hidden]=1&data[tt_content][123][title]=Hello%20World', true);
|
||||
$this->registerArgument('redirectUrl', 'string', 'Redirect URL if any other that \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv(\'REQUEST_URI\') is preferred', false, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a URL with a command to TYPO3 Core Engine - DataHandler (route tce_db)
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string URL to tce_db + parameters
|
||||
* @see \TYPO3\CMS\Backend\Utility\BackendUtility::getLinkToDataHandlerAction()
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$urlParameters = [
|
||||
'redirect' => $arguments['redirectUrl'] ?: GeneralUtility::getIndpEnv('REQUEST_URI')
|
||||
];
|
||||
if (isset($arguments['parameters'])) {
|
||||
$parametersArray = GeneralUtility::explodeUrl2Array($arguments['parameters']);
|
||||
$urlParameters += $parametersArray;
|
||||
}
|
||||
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
|
||||
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
|
||||
return (string)$uriBuilder->buildUriFromRoute('tce_db', $urlParameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Render permission icon group (user / group / others) of the "Access" module.
|
||||
*
|
||||
* Most of that could be done in fluid directly, but this ViewHelper
|
||||
* is much better performance wise.
|
||||
* @internal
|
||||
*/
|
||||
class PermissionsViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* @var array Cached labels for a single permission mask like "Delete page"
|
||||
*/
|
||||
protected static $permissionLabels = [];
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('permission', 'int', 'Current permission', true);
|
||||
$this->registerArgument('scope', 'string', '"user" / "group" / "everybody"', true);
|
||||
$this->registerArgument('pageId', 'int', '', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return permissions.
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return string
|
||||
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$masks = [1, 16, 2, 4, 8];
|
||||
|
||||
if (empty(static::$permissionLabels)) {
|
||||
foreach ($masks as $mask) {
|
||||
static::$permissionLabels[$mask] = LocalizationUtility::translate(
|
||||
'LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:' . $mask,
|
||||
'be_user'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$icon = '';
|
||||
foreach ($masks as $mask) {
|
||||
if ($arguments['permission'] & $mask) {
|
||||
$permissionClass = 'fa-check text-success';
|
||||
$mode = 'delete';
|
||||
} else {
|
||||
$permissionClass = 'fa-times text-danger';
|
||||
$mode = 'add';
|
||||
}
|
||||
|
||||
$label = static::$permissionLabels[$mask];
|
||||
$icon .= '<span style="cursor:pointer"'
|
||||
. ' title="' . htmlspecialchars($label) . '"'
|
||||
. ' data-toggle="tooltip"'
|
||||
. ' data-page="' . htmlspecialchars($arguments['pageId']) . '"'
|
||||
. ' data-permissions="' . htmlspecialchars($arguments['permission']) . '"'
|
||||
. ' data-who="' . htmlspecialchars($arguments['scope']) . '"'
|
||||
. ' data-bits="' . htmlspecialchars($mask) . '"'
|
||||
. ' data-mode="' . htmlspecialchars($mode) . '"'
|
||||
. ' class="t3-icon change-permission fa ' . htmlspecialchars($permissionClass) . '"></span>';
|
||||
}
|
||||
|
||||
return '<span id="' . htmlspecialchars($arguments['pageId'] . '_' . $arguments['scope']) . '">' . $icon . '</span>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Backend\Routing\UriBuilder;
|
||||
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Renders 'Delete user' link
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class RemoveUserViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('backendUser', BackendUser::class, 'Target backendUser to switch active session to', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the URL to remove a user.
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$urlParameters = [
|
||||
'cmd[be_users][' . $arguments['backendUser']->getUid() . '][delete]' => 1,
|
||||
'redirect' => GeneralUtility::getIndpEnv('REQUEST_URI')
|
||||
];
|
||||
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
|
||||
return (string)$uriBuilder->buildUriFromRoute('tce_db', $urlParameters);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Core\Imaging\Icon;
|
||||
use TYPO3\CMS\Core\Imaging\IconFactory;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Domain\Model\BackendUser;
|
||||
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
|
||||
/**
|
||||
* Views sprite icon for a record (object)
|
||||
* @internal
|
||||
*/
|
||||
class SpriteIconForRecordViewHelper extends AbstractBackendViewHelper
|
||||
{
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('table', 'string', '', true);
|
||||
$this->registerArgument('object', 'object', '', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays spriteIcon for database table and object
|
||||
*
|
||||
* @return string
|
||||
* @see IconFactory::getIconForRecord()
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return static::renderStatic($this->arguments, $this->buildRenderChildrenClosure(), $this->renderingContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$object = $arguments['object'];
|
||||
$table = $arguments['table'];
|
||||
|
||||
if (!is_object($object) || !method_exists($object, 'getUid')) {
|
||||
return '';
|
||||
}
|
||||
$row = [
|
||||
'uid' => $object->getUid(),
|
||||
'startTime' => false,
|
||||
'endTime' => false
|
||||
];
|
||||
if (method_exists($object, 'getIsDisabled')) {
|
||||
$row['disable'] = $object->getIsDisabled();
|
||||
}
|
||||
if (method_exists($object, 'getHidden')) {
|
||||
$row['hidden'] = $object->getHidden();
|
||||
}
|
||||
if ($table === 'be_users' && $object instanceof BackendUser) {
|
||||
$row['admin'] = $object->getIsAdministrator();
|
||||
}
|
||||
if (method_exists($object, 'getStartDateAndTime')) {
|
||||
$row['startTime'] = $object->getStartDateAndTime();
|
||||
}
|
||||
if (method_exists($object, 'getEndDateAndTime')) {
|
||||
$row['endTime'] = $object->getEndDateAndTime();
|
||||
}
|
||||
/** @var IconFactory $iconFactory */
|
||||
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
|
||||
return $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace TYPO3\CMS\Beuser\ViewHelpers;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
|
||||
use TYPO3\CMS\Core\Imaging\Icon;
|
||||
use TYPO3\CMS\Core\Imaging\IconFactory;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* Displays 'SwitchUser' link with sprite icon to change current backend user to target (non-admin) backendUser
|
||||
* @internal
|
||||
*/
|
||||
class SwitchUserViewHelper extends AbstractViewHelper
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
* Initializes the arguments
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('backendUser', BackendUser::class, 'Target backendUser to switch active session to', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render link with sprite icon to change current backend user to target
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
$backendUser = $arguments['backendUser'];
|
||||
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
|
||||
if ($backendUser->getUid() == $GLOBALS['BE_USER']->user['uid'] || !$backendUser->isActive() || $GLOBALS['BE_USER']->user['ses_backuserid']) {
|
||||
return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
|
||||
}
|
||||
$title = LocalizationUtility::translate('switchBackMode', 'beuser');
|
||||
return '<a class="btn btn-default" href="' .
|
||||
htmlspecialchars(GeneralUtility::linkThisScript(['SwitchUser' => $backendUser->getUid()])) .
|
||||
'" target="_top" title="' . htmlspecialchars($title) . '">' .
|
||||
$iconFactory->getIcon('actions-system-backend-user-switch', Icon::SIZE_SMALL)->render() . '</a>';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user