Skip to content

Commit

Permalink
[FEATURE] New API for the admin panel
Browse files Browse the repository at this point in the history
The admin panel consisted of one big god class
that contained the complete rendering.

The hook to extend the admin panel only allowed to
add content but not to add new modules (with expandable
headers).

The code has been refactored as a first step for a more
flexible admin panel:

- All modules are now rendered by a class per module
- Modules have an interface
- Modules can be registered in ext_localconf (and overwritten) using
the dependency ordering service for priority
- All new classes are strictly typed

Related: #84044
Resolves: #84045
Releases: master
Change-Id: I124bb503907dcfcbd4425d6f7178b87562d2fda4
Reviewed-on: https://review.typo3.org/55890
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
susannemoog authored and bmack committed Feb 27, 2018
1 parent 17fcf20 commit 61df57e
Show file tree
Hide file tree
Showing 15 changed files with 1,044 additions and 389 deletions.
@@ -0,0 +1,32 @@
.. include:: ../../Includes.txt

================================================
Deprecation: #84045 - AdminPanel Hook Deprecated
================================================

See :issue:`84045`

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

The hook `$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel']` has been deprecated along with the corresponding interface `\TYPO3\CMS\Frontend\View\AdminPanelViewHookInterface`.


Impact
======

Using either the interface or registering the hook will result in a deprecation error and will stop working in future TYPO3 versions.


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

Installations using the `\TYPO3\CMS\Frontend\View\AdminPanelViewHookInterface`.


Migration
=========

Use the new admin panel module API starting with TYPO3 v9 LTS.

.. index:: Frontend, FullyScanned, ext:frontend
@@ -0,0 +1,33 @@
.. include:: ../../Includes.txt

===========================================
Feature: #84045 - new AdminPanel module API
===========================================

See :issue:`84045`

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

Extending the Admin Panel was only partially possible in earlier TYPO3 versions by using a hook that provided the possibility to add pure content (no new modules) as plain HTML.

A new API has been introduced, providing more flexible options to add custom modules to the admin panel or replace and deactivate existing ones.


Impact
======

Custom admin panel modules can now be registered via `$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['frontend']['adminPanelModules']`.

.. code-block:: php
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['frontend']['adminPanelModules']['yourmodulename'] = [
'module' => \Vendor\Package\AdminPanel\YourModule::class,
'after' => ['preview']
]
To implement a custom module your module class has to implement the `\TYPO3\CMS\Frontend\AdminPanel\AdminPanelModuleInterface`.

Be aware that the `\TYPO3\CMS\Frontend\AdminPanel\AdminPanelModuleInterface` is not final yet and may change until v9 LTS.

.. index:: Frontend, PHP-API, ext:frontend
80 changes: 80 additions & 0 deletions typo3/sysext/frontend/Classes/AdminPanel/AbstractModule.php
@@ -0,0 +1,80 @@
<?php
declare(strict_types=1);

namespace TYPO3\CMS\Frontend\AdminPanel;

/*
* 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\FrontendBackendUserAuthentication;
use TYPO3\CMS\Core\Localization\LanguageService;

/**
* Abstract base class for Core Admin Panel Modules containing helper methods
*
* @internal
*/
abstract class AbstractModule implements AdminPanelModuleInterface
{
/**
* @inheritdoc
*/
public function getAdditionalJavaScriptCode(): string
{
return '';
}

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

/**
* 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
* @return string The value for the $key
*/
protected function extGetLL($key, $convertWithHtmlspecialchars = true): string
{
$labelStr = $this->getLanguageService()->getLL($key);
if ($convertWithHtmlspecialchars) {
$labelStr = htmlspecialchars($labelStr);
}
return $labelStr;
}

/**
* Returns LanguageService
*
* @return \TYPO3\CMS\Core\Localization\LanguageService
*/
protected function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}

/**
* Returns the current BE user.
*
* @return \TYPO3\CMS\Backend\FrontendBackendUserAuthentication
*/
protected function getBackendUser(): FrontendBackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace TYPO3\CMS\Frontend\AdminPanel;

/**
* Interface for admin panel modules registered via EXTCONF
*
* @internal until API is stable
*/
interface AdminPanelModuleInterface
{
/**
* Identifier for this module,
* for example "preview" or "cache"
*
* @return string
*/
public function getIdentifier(): string;

/**
* Module label
*
* @return string
*/
public function getLabel(): string;

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

/**
* Does this module need a form submit?
*
* @return bool
*/
public function showFormSubmitButton(): 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)
*
* @return string
*/
public function getAdditionalJavaScriptCode(): string;
}
87 changes: 87 additions & 0 deletions typo3/sysext/frontend/Classes/AdminPanel/CacheModule.php
@@ -0,0 +1,87 @@
<?php
declare(strict_types=1);

namespace TYPO3\CMS\Frontend\AdminPanel;

class CacheModule extends AbstractModule implements AdminPanelModuleInterface
{
/**
* Creates the content for the "cache" section ("module") of the Admin Panel
*
* @return string HTML content for the section. Consists of a string with table-rows with four columns.
*/
public function getContent(): string
{
$output = [];
if ($this->getBackendUser()->uc['TSFE_adminConfig']['display_cache']) {
$output[] = '<div class="typo3-adminPanel-form-group">';
$output[] = ' <div class="typo3-adminPanel-form-group-checkbox">';
$output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[cache_noCache]" value="0" />';
$output[] = ' <label for="cache_noCache">';
$output[] = ' <input type="checkbox" id="cache_noCache" name="TSFE_ADMIN_PANEL[cache_noCache]" value="1"' .
($this->getBackendUser()->uc['TSFE_adminConfig']['cache_noCache'] ? ' checked="checked"' : '') .
' />';
$output[] = ' ' . $this->extGetLL('cache_noCache');
$output[] = ' </label>';
$output[] = ' </div>';
$output[] = '</div>';

$levels = $this->getBackendUser()->uc['TSFE_adminConfig']['cache_clearCacheLevels'];
$output[] = '<div class="typo3-adminPanel-form-group">';
$output[] = ' <label for="cache_clearCacheLevels">';
$output[] = ' ' . $this->extGetLL('cache_clearLevels');
$output[] = ' </label>';
$output[] = ' <select id="cache_clearCacheLevels" name="TSFE_ADMIN_PANEL[cache_clearCacheLevels]">';
$output[] = ' <option value="0"' . ((int)$levels === 0 ? ' selected="selected"' : '') . '>';
$output[] = ' ' . $this->extGetLL('div_Levels_0');
$output[] = ' </option>';
$output[] = ' <option value="1"' . ($levels == 1 ? ' selected="selected"' : '') . '>';
$output[] = ' ' . $this->extGetLL('div_Levels_1');
$output[] = ' </option>';
$output[] = ' <option value="2"' . ($levels == 2 ? ' selected="selected"' : '') . '>';
$output[] = ' ' . $this->extGetLL('div_Levels_2');
$output[] = ' </option>';
$output[] = ' </select>';
$output[] = '</div>';

$output[] = '<div class="typo3-adminPanel-form-group">';
$output[] = ' <input type="hidden" name="TSFE_ADMIN_PANEL[cache_clearCacheId]" value="' .
$GLOBALS['TSFE']->id .
'" />';
$output[] = ' <input class="typo3-adminPanel-btn typo3-adminPanel-btn-default" type="submit" value="' .
$this->extGetLL('update') .
'" />';
$output[] = '</div>';
$output[] = '<div class="typo3-adminPanel-form-group">';
$output[] = ' <input class="typo3-adminPanel-btn typo3-adminPanel-btn-default" type="submit" name="TSFE_ADMIN_PANEL[action][clearCache]" value="' .
$this->extGetLL('cache_doit') .
'" />';
$output[] = '</div>';
}
return implode('', $output);
}

/**
* @inheritdoc
*/
public function getIdentifier(): string
{
return 'cache';
}

/**
* @inheritdoc
*/
public function getLabel(): string
{
return $this->extGetLL('cache');
}

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

0 comments on commit 61df57e

Please sign in to comment.