Skip to content

Commit

Permalink
[TASK] Refactor AdminPanelView - remove module specifics
Browse files Browse the repository at this point in the history
This is the second step in the AdminPanelView refactoring. It
extracts module specific code and uses a more generic API to
initialize, configure and display admin panel modules.

Resolves: #84118
Releases: master
Change-Id: I85a1e11dfd7d9397fabbfbd7d5cf658387056644
Reviewed-on: https://review.typo3.org/55985
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
  • Loading branch information
susannemoog authored and georgringer committed Mar 4, 2018
1 parent 13260d9 commit 3b39a1a
Show file tree
Hide file tree
Showing 16 changed files with 1,106 additions and 471 deletions.
@@ -0,0 +1,42 @@
.. include:: ../../Includes.txt

=========================================================================
Deprecation: #84118 - Various public methods of AdminPanelView deprecated
=========================================================================

See :issue:`84118`

Description
===========

To clean up the admin panel and provide a new API various functions of the main class `AdminPanelView` were deprecated:

* `getAdminPanelHeaderData`
* `isAdminModuleEnabled`
* `saveConfigOptions`
* `extGetFeAdminValue`
* `forcePreview`
* `isAdminModuleOpen`
* `extGetHead`
* `linkSectionHeader`
* `extGetItem`


Impact
======

Calling any of the mentioned methods triggers an `E_USER_DEPRECATED` PHP error.


Affected Installations
======================

Any installation that calls one of the above methods.


Migration
=========

Implement your own AdminPanel module by using the new API (see `AdminPanelModuleInterface`).

.. index:: Frontend, FullyScanned, ext:frontend
107 changes: 102 additions & 5 deletions typo3/sysext/frontend/Classes/AdminPanel/AbstractModule.php
Expand Up @@ -26,6 +26,7 @@
*/
abstract class AbstractModule implements AdminPanelModuleInterface
{

/**
* @inheritdoc
*/
Expand All @@ -34,6 +35,64 @@ public function getAdditionalJavaScriptCode(): string
return '';
}

/**
* @inheritdoc
*/
public function initializeModule(): void
{
}

/**
* Returns true if the module is
* -> either enabled via tsconfig admPanel.enable
* -> or any setting is overridden
* override is a way to use functionality of the admin panel without displaying the admin panel to users
* for example: hidden records or pages can be displayed by default
*
* @return bool
*/
public function isEnabled(): bool
{
$identifier = $this->getIdentifier();
$result = $this->isEnabledViaTsConfig();
if ($this->getBackendUser()->extAdminConfig['override.'][$identifier] ?? false) {
$result = (bool)$this->getBackendUser()->extAdminConfig['override.'][$identifier];
}
return $result;
}

/**
* Uses the backend user session to determine if the module is open
*
* @return bool
*/
public function isOpen(): bool
{
$option = 'display_' . $this->getIdentifier();
return isset($this->getBackendUser()->uc['TSFE_adminConfig'][$option])
? (bool)$this->getBackendUser()->uc['TSFE_adminConfig'][$option]
: false;
}

/**
* Determines if the panel for this module is shown
* -> returns true if panel is enabled in TSConfig
*
* @see isEnabled()
* @return bool
*/
public function isShown(): bool
{
return $this->isEnabledViaTsConfig();
}

/**
* @inheritdoc
*/
public function onSubmit(array $input): void
{
}

/**
* @inheritdoc
*/
Expand All @@ -46,7 +105,7 @@ public function showFormSubmitButton(): bool
* Translate given key
*
* @param string $key Key for a label in the $LOCAL_LANG array of "sysext/lang/Resources/Private/Language/locallang_tsfe.xlf
* @param bool $convertWithHtmlpecialchars If TRUE the language-label will be sent through htmlspecialchars
* @param bool $convertWithHtmlspecialchars If TRUE the language-label will be sent through htmlspecialchars
* @return string The value for the $key
*/
protected function extGetLL($key, $convertWithHtmlspecialchars = true): string
Expand All @@ -58,6 +117,37 @@ protected function extGetLL($key, $convertWithHtmlspecialchars = true): string
return $labelStr;
}

/**
* Returns the current BE user.
*
* @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
*/
protected function getBackendUser(): FrontendBackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}

/**
* Helper method to return configuration options
* Checks User TSConfig overrides and current backend user session
*
* @param string $option
* @return string
*/
protected function getConfigurationOption(string $option): string
{
$beUser = $this->getBackendUser();
$identifier = $this->getIdentifier();

if ($option && isset($beUser->extAdminConfig['override.'][$identifier . '.'][$option])) {
$returnValue = $beUser->extAdminConfig['override.'][$identifier . '.'][$option];
} else {
$returnValue = $beUser->uc['TSFE_adminConfig'][$identifier . '_' . $option] ?? '';
}

return (string)$returnValue;
}

/**
* Returns LanguageService
*
Expand All @@ -69,12 +159,19 @@ protected function getLanguageService(): LanguageService
}

/**
* Returns the current BE user.
* Returns true if TSConfig admPanel.enable is set for this module (or all modules)
*
* @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
* @return bool
*/
protected function getBackendUser(): FrontendBackendUserAuthentication
protected function isEnabledViaTsConfig(): bool
{
return $GLOBALS['BE_USER'];
$result = false;
$identifier = $this->getIdentifier();
if (!empty($this->getBackendUser()->extAdminConfig['enable.']['all'])) {
$result = true;
} elseif (!empty($this->getBackendUser()->extAdminConfig['enable.'][$identifier])) {
$result = true;
}
return $result;
}
}
Expand Up @@ -23,6 +23,22 @@
*/
interface AdminPanelModuleInterface
{
/**
* Additional JavaScript code for this module
* (you should only use vanilla JS here, as you cannot
* rely on the web site providing a specific framework)
*
* @return string
*/
public function getAdditionalJavaScriptCode(): string;

/**
* Module content as rendered HTML
*
* @return string
*/
public function getContent(): string;

/**
* Identifier for this module,
* for example "preview" or "cache"
Expand All @@ -39,25 +55,52 @@ public function getIdentifier(): string;
public function getLabel(): string;

/**
* Module content as rendered HTML
* Initialize the module - runs early in a TYPO3 request
*/
public function initializeModule(): void;

/**
* Module is enabled
* -> should be initialized
* A module may be enabled but not shown
* -> only the initializeModule() method
* will be called
*
* @return string
* @return bool
*/
public function getContent(): string;
public function isEnabled(): bool;

/**
* Does this module need a form submit?
* Module is open
* -> module is enabled
* -> module panel is shown and open
*
* @return bool
*/
public function showFormSubmitButton(): bool;
public function isOpen(): bool;

/**
* Additional JavaScript code for this module
* (you should only use vanilla JS here, as you cannot
* rely on the web site providing a specific framework)
* Module is shown
* -> module is enabled
* -> module panel should be displayed
*
* @return string
* @return bool
*/
public function getAdditionalJavaScriptCode(): string;
public function isShown(): bool;

/**
* Executed on saving / submit of the configuration form
* Can be used to react to changed settings
* (for example: clearing a specific cache)
*
* @param array $input
*/
public function onSubmit(array $input): void;

/**
* Does this module need a form submit?
*
* @return bool
*/
public function showFormSubmitButton(): bool;
}
44 changes: 44 additions & 0 deletions typo3/sysext/frontend/Classes/AdminPanel/CacheModule.php
Expand Up @@ -16,8 +16,12 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

class CacheModule extends AbstractModule
{

/**
* Creates the content for the "cache" section ("module") of the Admin Panel
*
Expand Down Expand Up @@ -90,11 +94,51 @@ public function getLabel(): string
return $this->extGetLL('cache');
}

/**
* @inheritdoc
*/
public function initializeModule(): void
{
if ($this->getConfigurationOption('noCache')) {
$this->getTypoScriptFrontendController()->set_no_cache('Admin Panel: No Caching', true);
}
}

/**
* Clear cache on saving if requested
*
* @param array $input
*/
public function onSubmit(array $input): void
{
if (($input['action']['clearCache'] ?? false) ||
isset($input['preview_showFluidDebug'])) {
$theStartId = (int)$input['cache_clearCacheId'];
$this->getTypoScriptFrontendController()
->clearPageCacheContent_pidList(
$this->getBackendUser()->extGetTreeList(
$theStartId,
(int)$this->getConfigurationOption('clearCacheLevels'),
0,
$this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW)
) . $theStartId
);
}
}

/**
* @inheritdoc
*/
public function showFormSubmitButton(): bool
{
return true;
}

/**
* @return TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
}

0 comments on commit 3b39a1a

Please sign in to comment.