Initial commit - Typo3 11.5.41
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace SGalinski\Lfeditor\Controller;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) sgalinski Internet Services (https://www.sgalinski.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 SGalinski\Lfeditor\Exceptions\LFException;
|
||||
use TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException;
|
||||
|
||||
/**
|
||||
* SearchConstant controller. It contains extbase actions for SearchConstant page.
|
||||
*/
|
||||
class SearchConstantController extends AbstractBackendController {
|
||||
/**
|
||||
* Opens searchConstant view.
|
||||
* It is called in 2 cases:
|
||||
* - on selection of searchConstant option in main menu,
|
||||
* - after redirection from action which must not change the view.
|
||||
*
|
||||
* @param bool $searchDone
|
||||
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
|
||||
*/
|
||||
public function searchConstantAction($searchDone = FALSE): ?\Psr\Http\Message\ResponseInterface {
|
||||
try {
|
||||
$this->view->assign('controllerName', 'SearchConstant');
|
||||
|
||||
$this->prepareExtensionAndLangFileOptions();
|
||||
$this->prepareSearchConstantViewMainSectionContent($searchDone);
|
||||
} catch (LFException $e) {
|
||||
$this->addLFEFlashMessage($e);
|
||||
}
|
||||
$this->commonViewRenderingActionSettings();
|
||||
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
|
||||
$this->view->assign('V11', FALSE);
|
||||
return NULL;
|
||||
} else {
|
||||
$this->view->assign('V11', TRUE);
|
||||
return $this->createBackendResponse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This action saves in session currently selected options from selection menus in searchConstant view.
|
||||
* It is called on change of selection of any select menu in searchConstant view.
|
||||
*
|
||||
* @param string $extensionSelection
|
||||
* @param string $languageFileSelection
|
||||
* @param string $extKey
|
||||
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
|
||||
*/
|
||||
public function changeSelectionAction($extensionSelection = NULL, $languageFileSelection = NULL, $extKey = ''): ?\Psr\Http\Message\ResponseInterface {
|
||||
$this->saveSelectionsInSession(
|
||||
$extensionSelection,
|
||||
$languageFileSelection,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
$extKey
|
||||
);
|
||||
|
||||
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
|
||||
$this->redirect('searchConstant');
|
||||
return NULL;
|
||||
} else {
|
||||
return $this->redirect('searchConstant');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the changes made in main section of searchConstant view.
|
||||
*
|
||||
* @param boolean $caseSensitive
|
||||
* @param string $searchStr
|
||||
*/
|
||||
public function searchConstantSearchAction($caseSensitive, $searchStr): ?\Psr\Http\Message\ResponseInterface {
|
||||
$searchResultArray = [];
|
||||
try {
|
||||
$this->configurationService->initFileObject(
|
||||
$this->session->getDataByKey('languageFileSelection'),
|
||||
$this->session->getDataByKey('extensionSelection')
|
||||
);
|
||||
$langData = $this->configurationService->getFileObj()->getLocalLangData();
|
||||
$viewLanguages = $this->configurationService->getLangArray($this->backendUser);
|
||||
|
||||
$searchOptions = $caseSensitive ? '' : 'i';
|
||||
if (!preg_match('/^\/.*\/.*$/', $searchStr) && !empty($searchStr)) {
|
||||
foreach ($viewLanguages as $langKey) {
|
||||
if (!array_key_exists($langKey, $langData) || !is_array($langData[$langKey])) {
|
||||
continue;
|
||||
}
|
||||
foreach ($langData[$langKey] as $labelKey => $labelValue) {
|
||||
$labelKeyOrValueContainSearchStr = preg_match(
|
||||
'/' . $searchStr . '/' . $searchOptions,
|
||||
$labelKey
|
||||
) || preg_match('/' . $searchStr . '/' . $searchOptions, $labelValue);
|
||||
if ($labelKeyOrValueContainSearchStr) {
|
||||
$searchResultArray[$langKey][$labelKey] = $labelValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!count($searchResultArray)) {
|
||||
throw new LFException('failure.search.noConstants', 1);
|
||||
}
|
||||
} else {
|
||||
throw new LFException('function.const.search.enterSearchStr', 1);
|
||||
}
|
||||
} catch (LFException $e) {
|
||||
$this->addLFEFlashMessage($e);
|
||||
}
|
||||
$this->session->setDataByKey('searchResultArray', $searchResultArray);
|
||||
$this->session->setDataByKey('searchString', $searchStr);
|
||||
$this->session->setDataByKey('searchCaseSensitive', $caseSensitive);
|
||||
|
||||
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
|
||||
$this->redirect('searchConstant', NULL, NULL, ['searchDone' => TRUE]);
|
||||
return NULL;
|
||||
} else {
|
||||
return $this->redirect('searchConstant', NULL, NULL, ['searchDone' => TRUE]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears extensionAndLangFileOptions cache, and in that way refreshes list of language file options in select box.
|
||||
*
|
||||
*/
|
||||
public function refreshLanguageFileListAction(): ?\Psr\Http\Message\ResponseInterface {
|
||||
$this->clearSelectOptionsCache('extensionAndLangFileOptions');
|
||||
|
||||
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
|
||||
$this->redirect('searchConstant', NULL, NULL, ['searchDone' => TRUE]);
|
||||
return NULL;
|
||||
} else {
|
||||
return $this->redirect('searchConstant', NULL, NULL, ['searchDone' => TRUE]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares main section content of searchConstant view.
|
||||
*
|
||||
* @param bool $searchDone
|
||||
* @return void
|
||||
*/
|
||||
protected function prepareSearchConstantViewMainSectionContent($searchDone) {
|
||||
$searchResultArray = [];
|
||||
if ($searchDone) {
|
||||
$searchResultArray = $this->session->getDataByKey('searchResultArray');
|
||||
} else {
|
||||
$this->session->setDataByKey('searchResultArray', []);
|
||||
}
|
||||
$searchString = $this->session->getDataByKey('searchString');
|
||||
$searchCaseSensitive = $this->session->getDataByKey('searchCaseSensitive');
|
||||
|
||||
$this->view->assign('searchResultArray', $searchResultArray);
|
||||
$this->view->assign('searchString', $searchString);
|
||||
$this->view->assign('searchCaseSensitive', $searchCaseSensitive);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user