first commit
This commit is contained in:
69
Classes/ViewHelpers/Backend/Button/HelpButtonViewHelper.php
Normal file
69
Classes/ViewHelpers/Backend/Button/HelpButtonViewHelper.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\ViewHelpers\Backend\Button;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2013-2015 Ingo Renner <ingo@typo3.org>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrViewHelper;
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* View helper to return a help button
|
||||
*
|
||||
*/
|
||||
class HelpButtonViewHelper extends AbstractSolrViewHelper implements ViewHelperInterface
|
||||
{
|
||||
use CompileWithRenderStatic;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $escapeOutput = false;
|
||||
|
||||
/**
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
$this->registerArgument('title', 'string', 'Title', true);
|
||||
$this->registerArgument('description', 'string', 'Description', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a help button wit the given title and content
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param \Closure $renderChildrenClosure
|
||||
* @param RenderingContextInterface $renderingContext
|
||||
* @return string
|
||||
*/
|
||||
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
|
||||
{
|
||||
return BackendUtility::wrapInHelp('', '', '', [
|
||||
'title' => $arguments['title'],
|
||||
'description' => $arguments['description']
|
||||
]);
|
||||
}
|
||||
}
|
57
Classes/ViewHelpers/Backend/IsStringViewHelper.php
Normal file
57
Classes/ViewHelpers/Backend/IsStringViewHelper.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\ViewHelpers\Backend;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2017 Rafael Kähm <rafael.kaehm@dkd.de>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
|
||||
/**
|
||||
* Condition for checking if type is a string.
|
||||
*/
|
||||
class IsStringViewHelper extends AbstractConditionViewHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* Initialize ViewHelper arguments
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('value', 'mixed', 'Value to be verified.', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decides if the condition is true or false
|
||||
*
|
||||
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper.
|
||||
* @return bool
|
||||
*/
|
||||
protected static function evaluateCondition($arguments = null)
|
||||
{
|
||||
return (isset($arguments['value']) && is_string($arguments['value']));
|
||||
}
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\ViewHelpers\Backend\Security;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2010-2017 dkd Internet Service GmbH <solr-support@dkd.de>
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
* free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The GNU General Public License can be found at
|
||||
* http://www.gnu.org/copyleft/gpl.html.
|
||||
*
|
||||
* This script is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
|
||||
|
||||
/**
|
||||
* This view helper implements an ifHasAccessToModule/else condition for BE users/groups.
|
||||
*
|
||||
* Class IfHasAccessToModuleViewHelper
|
||||
*/
|
||||
class IfHasAccessToModuleViewHelper extends AbstractConditionViewHelper
|
||||
{
|
||||
/**
|
||||
* Message for that case, if $arguments['signature'] was used and module does not exist
|
||||
* @var string
|
||||
*/
|
||||
const ERROR_APPENDIX_FOR_WRONG_SIGNATURE_ARGUMENT = 'Please check spelling and style by setting signature="mainName_ExtKeySubmoduleName".';
|
||||
|
||||
/**
|
||||
* Message for that case, if $arguments['extension'], $arguments['main'] and $arguments['sub'] are used and module couldn't be resolved
|
||||
* @var string
|
||||
*/
|
||||
const ERROR_APPENDIX_FOR_SIGNATURE_RESOLUTION = 'It was generated by setting extension="%s", main="%s", sub="%s", please check spelling and style by setting this arguments.';
|
||||
|
||||
/**
|
||||
* Initializes following arguments: extension, main, sub, signature
|
||||
* Renders <f:then> child if the current logged in BE user belongs to the specified role (aka usergroup)
|
||||
* otherwise renders <f:else> child.
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
parent::initializeArguments();
|
||||
$this->registerArgument('extension', 'string', 'The extension key.');
|
||||
$this->registerArgument('main', 'string', 'The main module name.');
|
||||
$this->registerArgument('sub', 'string', 'The sub module name.');
|
||||
$this->registerArgument('signature', 'string', 'The full signature of module. Simply mainmodulename_submodulename in most cases.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate condition
|
||||
*
|
||||
* @param null $arguments
|
||||
* @return bool
|
||||
*/
|
||||
protected static function evaluateCondition($arguments = null)
|
||||
{
|
||||
/* @var BackendUserAuthentication $beUser */
|
||||
$beUser = $GLOBALS['BE_USER'];
|
||||
try {
|
||||
$hasAccessToModule = $beUser->modAccess(
|
||||
self::getModuleConfiguration(self::getModuleSignatureFromArguments($arguments))
|
||||
);
|
||||
} catch (\RuntimeException $exception) {
|
||||
return false;
|
||||
}
|
||||
return $hasAccessToModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the backend module configuration
|
||||
*
|
||||
* @param string $moduleSignature
|
||||
* @return mixed
|
||||
*/
|
||||
protected static function getModuleConfiguration(string $moduleSignature)
|
||||
{
|
||||
return $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves
|
||||
*
|
||||
* @param array $arguments
|
||||
* @return mixed|string
|
||||
*/
|
||||
protected static function getModuleSignatureFromArguments(array $arguments)
|
||||
{
|
||||
$moduleSignature = $arguments['signature'];
|
||||
|
||||
$possibleErrorMessageAppendix = self::ERROR_APPENDIX_FOR_WRONG_SIGNATURE_ARGUMENT;
|
||||
$possibleErrorCode = 1496311009;
|
||||
if (!is_string($moduleSignature)) {
|
||||
$moduleSignature = $arguments['main'];
|
||||
$subModuleName = $arguments['extension'] . GeneralUtility::underscoredToUpperCamelCase($arguments['sub']);
|
||||
$moduleSignature .= '_' . $subModuleName;
|
||||
$possibleErrorMessageAppendix = vsprintf(self::ERROR_APPENDIX_FOR_SIGNATURE_RESOLUTION, [$arguments['extension'], $arguments['main'], $arguments['sub']]);
|
||||
$possibleErrorCode = 1496311010;
|
||||
}
|
||||
if (!isset($GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature])) {
|
||||
throw new \RuntimeException(vsprintf('Module with signature "%s" is not configured or couldn\'t be resolved. ' . $possibleErrorMessageAppendix, [$moduleSignature]), $possibleErrorCode);
|
||||
}
|
||||
return $moduleSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates arguments given to this view helper.
|
||||
*
|
||||
* It checks if either signature or extension and main and sub are set.
|
||||
*/
|
||||
public function validateArguments()
|
||||
{
|
||||
parent::validateArguments();
|
||||
|
||||
if (empty($this->arguments['signature'])
|
||||
&& (empty($this->arguments['extension']) || empty($this->arguments['main']) || empty($this->arguments['sub'])
|
||||
)
|
||||
) {
|
||||
throw new \InvalidArgumentException('ifHasAccessToModule view helper requires either "signature" or all three other arguments: "extension", "main" and "sub". Please set arguments properly.', 1496314352);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user