Skip to content
Snippets Groups Projects
Commit 64482660 authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Initial code for backend module

parent 1b8a0735
No related branches found
Tags 5.6.6
1 merge request!2Feature be module
Showing
with 629 additions and 0 deletions
<?php
namespace SGalinski\SgNews\Controller\Backend;
/***************************************************************
* 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\SgNews\Service\Backend\Utility;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
/**
* News Controller
*/
class NewsController extends ActionController {
/**
* DocHeaderComponent
*
* @var DocHeaderComponent
*/
protected $docHeaderComponent;
/**
* @var \SGalinski\SgNews\Domain\Repository\NewsRepository
* @inject
*/
private $newsRepository;
/**
* @var \SGalinski\SgNews\Domain\Repository\CategoryRepository
* @inject
*/
private $categoryRepository;
/**
* @var \SGalinski\SgNews\Domain\Repository\TagRepository
* @inject
*/
private $tagRepository;
public function indexAction() {
// create doc header component
$pageUid = (int) GeneralUtility::_GP('id');
/** @var BackendUserAuthentication $backendUser */
$backendUser = $GLOBALS['BE_USER'];
$pageInfo = BackendUtility::readPageAccess($pageUid, $backendUser->getPagePermsClause(1));
$this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
$this->docHeaderComponent->setMetaInformation($pageInfo);
Utility::makeButtons($this->docHeaderComponent, $this->request);
$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
$this->view->assign('pageUid', $pageUid);
}
}
<?php
namespace SGalinski\SgNews\Service\Backend;
/***************************************************************
* 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 TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* Class Utility
*/
class Utility {
/**
* create buttons for the backend module header
*
* @param $docHeaderComponent DocHeaderComponent
* @param $request Request
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
*/
public static function makeButtons(&$docHeaderComponent, &$request) {
/** @var ButtonBar $buttonBar */
$buttonBar = $docHeaderComponent->getButtonBar();
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
// Refresh
$refreshButton = $buttonBar->makeLinkButton()
->setHref(GeneralUtility::getIndpEnv('REQUEST_URI'))
->setTitle(LocalizationUtility::translate('LLL:EXT:lang/locallang_core.xlf:labels.reload', ''))
->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
$buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);
// shortcut button
$shortcutButton = $buttonBar->makeShortcutButton()
->setModuleName($request->getPluginName())
->setGetVariables(
[
'id',
'M'
]
)
->setSetVariables([]);
$buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT);
$docHeaderComponent->getButtonBar();
}
}
<?php
namespace SGalinski\SgNews\ViewHelpers\Backend;
/***************************************************************
* 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 TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
/**
* Class ControlViewHelper
**/
class ControlViewHelper extends AbstractViewHelper {
/**
* Renders the control buttons for the specified record
*
* @param string $table
* @param mixed $row
* @return string
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
*/
public function render($table, $row) {
/** @var DatabaseRecordList $databaseRecordList */
$databaseRecordList = GeneralUtility::makeInstance(DatabaseRecordList::class);
/** @var BackendUserAuthentication $backendUser */
$backendUser = $GLOBALS['BE_USER'];
$pageInfo = BackendUtility::readPageAccess($row['pid'], $backendUser->getPagePermsClause(1));
$databaseRecordList->calcPerms = $GLOBALS['BE_USER']->calcPerms($pageInfo);
return $databaseRecordList->makeControl($table, $row);
}
}
<?php
namespace SGalinski\SgNews\ViewHelpers\Backend;
/***************************************************************
* 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 TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Class EditOnClickViewHelper
**/
class EditOnClickViewHelper extends AbstractViewHelper {
/**
* Renders the onclick script for editing a record
*
* @param string $table
* @param int $uid
* @param boolean $new
* @return string
*/
public function render($table, $uid, $new = FALSE) {
return BackendUtility::editOnClick('&edit[' . $table . '][' . $uid . ']=' . ($new ? 'new' : 'edit'), '', -1);
}
}
<?php
namespace SGalinski\SgNews\ViewHelpers\Backend;
/***************************************************************
* 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 TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Class IconViewHelper
**/
class IconViewHelper extends AbstractViewHelper {
/**
* Renders the icon for the specified record
*
* @param string $table
* @param mixed $row
* @param boolean $clickMenu
* @return string
* @throws \InvalidArgumentException
*/
public function render($table, $row, $clickMenu = TRUE) {
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$toolTip = BackendUtility::getRecordToolTip($row, $table);
$iconImg = '<span ' . $toolTip . '>'
. $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render()
. '</span>';
if ($clickMenu) {
return BackendUtility::wrapClickMenuOnIcon($iconImg, $table, $row['uid']);
} else {
return $iconImg;
}
}
}
<?php
namespace SGalinski\SgNews\ViewHelpers\Backend\Widget\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!
***************************************************************/
/**
* Class PaginateController
*/
class PaginateController extends \TYPO3\CMS\Fluid\ViewHelpers\Be\Widget\Controller\PaginateController {
/**
* @var mixed
*/
protected $objects;
/**
* Renders the paginator
*
* @param int $currentPage
* @return void
*/
public function indexAction($currentPage = 1) {
// set current page
$this->currentPage = (int) $currentPage;
if ($this->currentPage < 1) {
$this->currentPage = 1;
}
if ($this->currentPage > $this->numberOfPages) {
// set $modifiedObjects to NULL if the page does not exist
$modifiedObjects = NULL;
} else {
// modify query
$this->itemsPerPage = (int) $this->configuration['itemsPerPage'];
$this->offset = $this->itemsPerPage * ($this->currentPage - 1);
if (is_array($this->objects)) {
$modifiedObjects = [];
for ($index = $this->offset; $index < $this->offset + $this->itemsPerPage; $index++) {
if (isset($this->objects[$index])) {
$modifiedObjects[] = $this->objects[$index];
} else {
break;
}
}
} else {
$query = $this->objects->getQuery();
$query->setLimit($this->itemsPerPage);
if ($this->currentPage > 1) {
$query->setOffset($this->offset);
}
$modifiedObjects = $query->execute();
}
}
$this->view->assign(
'contentArguments', [
$this->widgetConfiguration['as'] => $modifiedObjects
]
);
$this->view->assign('configuration', $this->configuration);
$this->view->assign('pagination', $this->buildPagination());
}
/**
* Returns an array with the keys "pages", "current", "numberOfPages",
* "nextPage" & "previousPage"
*
* @return array
*/
protected function buildPagination() {
$pagination = parent::buildPagination();
$pagination['totalObjects'] = count($this->objects);
return $pagination;
}
}
<?php
namespace SGalinski\SgNews\ViewHelpers\Backend\Widget;
/***************************************************************
* 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\SgRoutes\ViewHelpers\Backend\Widget\Controller\PaginateController;
use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper;
/**
* Class PaginateViewHelper
*/
class PaginateViewHelper extends AbstractWidgetViewHelper {
/**
* @var \SGalinski\SgRoutes\ViewHelpers\Backend\Widget\Controller\PaginateController
*/
protected $controller;
/**
* Initializes the controller
*
* @param PaginateController $controller
*/
public function injectPaginateController(
PaginateController $controller
) {
$this->controller = $controller;
}
/**
* Renders the paginator
*
* @param mixed $objects
* @param string $as
* @param array $configuration
* @return string
*/
public function render(
$objects, $as,
array $configuration = ['itemsPerPage' => 10, 'insertAbove' => FALSE, 'insertBelow' => TRUE, 'recordsLabel' => '']
) {
return $this->initiateSubRequest();
}
}
module.tx_sgnews {
settings < plugin.tx_sgnews.settings
persistence < plugin.tx_sgnews.persistence
view < plugin.tx_sgnews.view
view {
# cat=plugin.tx_sgnews/file; type=string; label=Path to template root (FE)
templateRootPaths {
10 = EXT:sg_news/Resources/Private/Backend/Templates/
}
# cat=plugin.tx_sgnews/file; type=string; label=Path to template partials (FE)
partialRootPaths {
10 = EXT:sg_news/Resources/Private/Backend/Partials/
}
# cat=plugin.tx_sgnews/file; type=string; label=Path to template layouts (FE)
layoutRootPaths {
10 = EXT:sg_news/Resources/Private/Backend/Layouts/
}
}
}
module.tx_sgnews {
settings < plugin.tx_sgnews.settings
persistence < plugin.tx_sgnews.persistence
view < plugin.tx_sgnews.view
view {
# cat=plugin.tx_sgnews/file; type=string; label=Path to template root (FE)
templateRootPaths {
10 = {$module.tx_sgnews.view.templateRootPaths.10}
}
# cat=plugin.tx_sgnews/file; type=string; label=Path to template partials (FE)
partialRootPaths {
10 = {$module.tx_sgnews.view.partialRootPaths.10}
}
# cat=plugin.tx_sgnews/file; type=string; label=Path to template layouts (FE)
layoutRootPaths {
10 = {$module.tx_sgnews.view.layoutRootPaths.10}
}
}
}
{namespace core = TYPO3\CMS\Core\ViewHelpers}
{namespace sg=SGalinski\SgNews\ViewHelpers}
<f:be.container enableClickMenu="FALSE" loadExtJs="FALSE"
includeRequireJsModules="{
0: 'TYPO3/CMS/Backend/AjaxDataHandler',
1: '{f:if(condition: \'{typo3Version} < 8000000 \', then: \'TYPO3/CMS/Backend/ClickMenu\', else: \'TYPO3/CMS/Backend/ContextMenu\')}',
2: 'TYPO3/CMS/Backend/Tooltip'}">
<sg:addJavaScriptFile javaScriptFile="{f:uri.resource(path: 'Scripts/Backend.js')}" />
<f:format.raw>
<sg:inlineLanguageLabels labels="backend.delete_route, backend.delete_all, backend.htaccess" />
</f:format.raw>
<div class="module" data-module-id="" data-module-name="">
<div class="module-docheader t3js-module-docheader">
<div class="module-docheader-bar module-docheader-bar-navigation t3js-module-docheader-bar t3js-module-docheader-bar-navigation">
<div class="module-docheader-bar-column-left">
</div>
<div class="module-docheader-bar-column-right">
<span class="typo3-docheader-pagePath"><f:translate key="LLL:EXT:lang/locallang_core.xlf:labels.path" />: <f:format.raw>{docHeader.metaInformation.path}</f:format.raw></span>
<f:format.raw>{docHeader.metaInformation.recordInformation}</f:format.raw>
</div>
</div>
<div class="module-docheader-bar module-docheader-bar-buttons t3js-module-docheader-bar t3js-module-docheader-bar-buttons">
<div class="module-docheader-bar-column-left">
<div class="btn-toolbar" role="toolbar" aria-label="">
<f:render section="iconButtons" />
</div>
</div>
<div class="module-docheader-bar-column-right">
<f:render partial="ButtonBar" arguments="{buttons:docHeader.buttons.right}" />
</div>
</div>
</div>
</div>
<div id="typo3-docbody">
<div id="typo3-inner-docbody">
<h1>
<f:render section="headline" />
</h1>
<f:render section="content" />
</div>
</div>
</f:be.container>
<div class="btn-toolbar" role="toolbar" aria-label="">
<f:for each="{buttons}" as="buttonGroup">
<f:if condition="{buttonGroup -> f:count()} > 1">
<f:then>
<div class="btn-group" role="group" aria-label="">
<f:for each="{buttonGroup}" as="button">
{button -> f:format.raw()}
</f:for>
</div>
</f:then>
<f:else>
{buttonGroup.0 -> f:format.raw()}
</f:else>
</f:if>
</f:for>
</div>
{namespace sg=SGalinski\SgRoutes\ViewHelpers}
<f:layout name="Default" />
<f:section name="iconButtons">
</f:section>
<f:section name="content">
<f:flashMessages />
<p>
<f:translate key="backend.message" />
</p>
</f:section>
......@@ -13,6 +13,17 @@ $extPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('sg_news'
$tsPath = $extPath . 'Configuration/TypoScript/Common/';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup(file_get_contents($tsPath . 'setup.txt'));
// backend typoscript configuration
if (TYPO3_MODE === 'BE') {
$tsPath = $extPath . 'Configuration/TypoScript/Backend/';
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptConstants(
file_get_contents($tsPath . 'constants.txt')
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptSetup(file_get_contents($tsPath . 'setup.txt'));
}
// plugin configurations
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'SGalinski.sg_news',
......
......@@ -28,6 +28,23 @@ TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'LLL:EXT:sg_news/Resources/Private/Language/locallang_backend.xlf:titleListByCategoryPlugin'
);
if (TYPO3_MODE === 'BE') {
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
'SGalinski.sg_news',
'web',
'News',
'',
[
'Backend\News' => 'index',
],
[
'access' => 'user,group',
'icon' => 'EXT:sg_news/Resources/Public/Images/News.png',
'labels' => 'LLL:EXT:sg_news/Resources/Private/Language/locallang.xlf',
]
);
}
// Removal of the unused plugin setting fields
$TCA['tt_content']['types']['list']['subtypes_excludelist']['sgnews_overview'] = 'select_key,pages,recursive';
$TCA['tt_content']['types']['list']['subtypes_excludelist']['sgnews_listbycategory'] = 'select_key,pages,recursive';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment