mirror of
https://github.com/FriendsOfTYPO3/feedit.git
synced 2024-11-23 06:36:09 +01:00
[TASK] Add feedit specific code from ext:adminpanel
This commit is contained in:
parent
52c17e342e
commit
a4d92d0c5e
6 changed files with 227 additions and 0 deletions
148
Classes/Modules/EditModule.php
Normal file
148
Classes/Modules/EditModule.php
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace TYPO3\CMS\Feedit\Modules;
|
||||
|
||||
/*
|
||||
* 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 Psr\Http\Message\ServerRequestInterface;
|
||||
use TYPO3\CMS\Adminpanel\ModuleApi\AbstractModule;
|
||||
use TYPO3\CMS\Adminpanel\ModuleApi\InitializableInterface;
|
||||
use TYPO3\CMS\Adminpanel\ModuleApi\PageSettingsProviderInterface;
|
||||
use TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface;
|
||||
use TYPO3\CMS\Adminpanel\Service\EditToolbarService;
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Fluid\View\StandaloneView;
|
||||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
||||
|
||||
/**
|
||||
* Admin Panel Edit Module
|
||||
*/
|
||||
class EditModule extends AbstractModule implements PageSettingsProviderInterface, InitializableInterface, ResourceProviderInterface
|
||||
{
|
||||
/**
|
||||
* Creates the content for the "edit" 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 getPageSettings(): string
|
||||
{
|
||||
$editToolbarService = GeneralUtility::makeInstance(EditToolbarService::class);
|
||||
$toolbar = $editToolbarService->createToolbar();
|
||||
$view = GeneralUtility::makeInstance(StandaloneView::class);
|
||||
$templateNameAndPath = 'EXT:feedit/Resources/Private/Templates/Modules/Settings/Edit.html';
|
||||
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateNameAndPath));
|
||||
$view->setPartialRootPaths(['EXT:feedit/Resources/Private/Partials']);
|
||||
$view->assignMultiple(
|
||||
[
|
||||
'display' => [
|
||||
'fieldIcons' => $this->configurationService->getConfigurationOption('edit', 'displayFieldIcons'),
|
||||
'displayIcons' => $this->configurationService->getConfigurationOption('edit', 'displayIcons'),
|
||||
],
|
||||
'toolbar' => $toolbar,
|
||||
'script' => [
|
||||
'pageUid' => (int)$this->getTypoScriptFrontendController()->page['uid'],
|
||||
'pageModule' => $this->getPageModule(),
|
||||
'backendScript' => BackendUtility::getBackendScript(),
|
||||
't3BeSitenameMd5' => md5('Typo3Backend-' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']),
|
||||
],
|
||||
]
|
||||
);
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TypoScriptFrontendController
|
||||
*/
|
||||
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
|
||||
{
|
||||
return $GLOBALS['TSFE'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getPageModule(): string
|
||||
{
|
||||
$pageModule = trim($this->getBackendUser()->getTSConfig()['options.']['overridePageModule'] ?? '');
|
||||
return BackendUtility::isModuleSetInTBE_MODULES($pageModule) ? $pageModule : 'web_layout';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return 'edit';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getIconIdentifier(): string
|
||||
{
|
||||
return 'actions-open';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getLabel(): string
|
||||
{
|
||||
$locallangFileAndPath = 'LLL:EXT:feedit/Resources/Private/Language/locallang_edit.xlf:module.label';
|
||||
return $this->getLanguageService()->sL($locallangFileAndPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the edit module
|
||||
* Includes the frontend edit initialization
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
*/
|
||||
public function initializeModule(ServerRequestInterface $request): void
|
||||
{
|
||||
$typoScriptFrontend = $this->getTypoScriptFrontendController();
|
||||
$typoScriptFrontend->displayEditIcons = $this->configurationService->getConfigurationOption('edit', 'displayIcons');
|
||||
$typoScriptFrontend->displayFieldEditIcons = $this->configurationService->getConfigurationOption('edit', 'displayFieldIcons');
|
||||
|
||||
if ($request->getQueryParams()['ADMCMD_editIcons'] ?? $request->getParsedBody()['ADMCMD_editIcons'] ?? false) {
|
||||
$typoScriptFrontend->displayFieldEditIcons = '1';
|
||||
}
|
||||
if ($typoScriptFrontend->displayEditIcons) {
|
||||
$typoScriptFrontend->set_no_cache('Admin Panel: Display edit icons', true);
|
||||
}
|
||||
if ($typoScriptFrontend->displayFieldEditIcons) {
|
||||
$typoScriptFrontend->set_no_cache('Admin Panel: Display field edit icons', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getJavaScriptFiles(): array
|
||||
{
|
||||
return ['EXT:feedit/Resources/Public/JavaScript/Modules/Edit.js'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string array with css files that will be rendered after the module
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCssFiles(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
21
Resources/Private/Language/locallang_edit.xlf
Normal file
21
Resources/Private/Language/locallang_edit.xlf
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
|
||||
<file t3:id="1521629227" source-language="en" datatype="plaintext" original="messages" date="2018-03-21T11:47:00Z"
|
||||
product-name="feedit">
|
||||
<header/>
|
||||
<body>
|
||||
<trans-unit id="module.label">
|
||||
<source>Edit</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="displayFieldIcons">
|
||||
<source>Display edit icons</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="displayIcons">
|
||||
<source>Display edit panels</source>
|
||||
</trans-unit>
|
||||
<trans-unit id="openAB">
|
||||
<source>Open TYPO3 Backend</source>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
13
Resources/Private/Partials/Form/Checkbox.html
Normal file
13
Resources/Private/Partials/Form/Checkbox.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
|
||||
<f:if condition="{label} && {name}">
|
||||
<div class="typo3-adminPanel-form-group typo3-adminPanel-form-group-checkbox">
|
||||
<div class="typo3-adminPanel-form-checkbox">
|
||||
<input type="hidden" name="TSFE_ADMIN_PANEL[{name}]" value="0"/>
|
||||
<input type="checkbox" id="{name}" name="TSFE_ADMIN_PANEL[{name}]" value="1" class="typo3-adminPanel-form-checkbox-input"{f:if(condition: value, then:' checked="checked"')} />
|
||||
<label for="{name}" class="typo3-adminPanel-form-checkbox-label">
|
||||
<f:translate key="{label}" default="{label}" extensionName="adminpanel"/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</f:if>
|
||||
</html>
|
16
Resources/Private/Templates/Modules/Settings/Edit.html
Normal file
16
Resources/Private/Templates/Modules/Settings/Edit.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
|
||||
<f:render partial="Form/Checkbox" arguments="{
|
||||
label: 'LLL:EXT:feedit/Resources/Private/Language/locallang_edit.xlf:displayFieldIcons',
|
||||
name: 'edit_displayFieldIcons',
|
||||
value: display.fieldIcons }" debug="false"/>
|
||||
<f:render partial="Form/Checkbox" arguments="{
|
||||
label: 'LLL:EXT:feedit/Resources/Private/Language/locallang_edit.xlf:displayIcons',
|
||||
name: 'edit_displayIcons',
|
||||
value: display.displayIcons }" debug="false"/>
|
||||
<f:format.raw>{toolbar}</f:format.raw>
|
||||
<div class="typo3-adminPanel-form-group">
|
||||
<a class="typo3-adminPanel-btn typo3-adminPanel-btn-default typo3-adminPanel-btn-openBackend" href="#" data-pageUid="{script.pageUid}" data-pageModule="{script.pageModule}" data-t3BeSitenameMd5="{script.t3BeSitenameMd5}" data-backendScript="{script.backendScript}">
|
||||
<f:translate key="LLL:EXT:feedit/Resources/Private/Language/locallang_edit.xlf:openAB"/>
|
||||
</a>
|
||||
</div>
|
||||
</html>
|
24
Resources/Public/JavaScript/Modules/Edit.js
Normal file
24
Resources/Public/JavaScript/Modules/Edit.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
function editModuleOnClickHandler(event) {
|
||||
event.preventDefault();
|
||||
var element = event.target;
|
||||
if (parent.opener && parent.opener.top) {
|
||||
parent.opener.top.fsMod.recentIds['web'] = element.getAttribute('data-pageUid');
|
||||
if (parent.opener.top && parent.opener.top.nav_frame && parent.opener.top.nav_frame.refresh_nav) {
|
||||
parent.opener.top.nav_frame.refresh_nav();
|
||||
}
|
||||
parent.opener.top.goToModule(element.getAttribute('data-pageModule'));
|
||||
parent.opener.top.focus();
|
||||
} else {
|
||||
var vHWin = window.open(element.getAttribute('data-backendScript'), element.getAttribute('data-t3BeSitenameMd5'));
|
||||
vHWin.focus();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function initializeEditModule() {
|
||||
var editModuleBtnOpenBackend = document.querySelector('.typo3-adminPanel-btn-openBackend');
|
||||
editModuleBtnOpenBackend.addEventListener('click', editModuleOnClickHandler);
|
||||
}
|
||||
|
||||
|
||||
window.addEventListener('load', initializeEditModule, false);
|
|
@ -3,3 +3,8 @@ defined('TYPO3_MODE') or die();
|
|||
|
||||
// Register the edit panel view.
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/classes/class.frontendedit.php']['edit'] = \TYPO3\CMS\Feedit\FrontendEditPanel::class;
|
||||
|
||||
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']['edit'] = [
|
||||
'module' => \TYPO3\CMS\Feedit\Modules\EditModule::class,
|
||||
'after' => ['cache'],
|
||||
];
|
Loading…
Reference in a new issue