Skip to content

Commit

Permalink
[FEATURE] Make position of sys notes configurable
Browse files Browse the repository at this point in the history
Add a new field "position" to allow editors to define where the
sys_note record is rendered.

Resolves: #83965
Releases: master
Change-Id: I22c6b5c66ce5ab58a112f844fd763a18788552f9
Reviewed-on: https://review.typo3.org/55976
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Guido Schmechel <littlegee@web.de>
Tested-by: Guido Schmechel <littlegee@web.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
georgringer authored and bmack committed Mar 3, 2018
1 parent a25e07a commit 13260d9
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. include:: ../../Includes.txt

=========================================================
Feature: #83965 - Make position of sys notes configurable
=========================================================

See :issue:`83965`

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

Sys_note records can now be rendered either in the top or bottom of the page and list module by
defining the position in the record itself.

.. index:: Backend, ext:sys_note
5 changes: 3 additions & 2 deletions typo3/sysext/sys_note/Classes/Controller/NoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ public function __construct()
* Render notes by single PID or PID list
*
* @param string $pids Single PID or comma separated list of PIDs
* @param int|null $position null for no restriction, integer for defined position
* @return string
*/
public function listAction($pids): string
public function listAction($pids, int $position = null): string
{
if (empty($pids) || empty($GLOBALS['BE_USER']->user['uid'])) {
return '';
}

$notes = $this->notesRepository->findByPidsAndAuthorId($pids, (int)$GLOBALS['BE_USER']->user['uid']);
$notes = $this->notesRepository->findByPidsAndAuthorId($pids, (int)$GLOBALS['BE_USER']->user['uid'], $position);
if ($notes) {
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@
*/
class SysNoteRepository
{
const SYS_NOTE_POSITION_BOTTOM = 0;
const SYS_NOTE_POSITION_TOP = 1;

/**
* Find notes by given pids and author
*
* @param string $pids Single PID or comma separated list of PIDs
* @param int $author author uid
* @param int|null $position null for no restriction, integer for defined position
* @return array
*/
public function findByPidsAndAuthorId($pids, int $author): array
public function findByPidsAndAuthorId($pids, int $author, int $position = null): array
{
$pids = GeneralUtility::intExplode(',', (string)$pids);

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_note');
$rows = $queryBuilder
$res = $queryBuilder
->select('sys_note.*', 'be_users.username', 'be_users.realName')
->from('sys_note')
->leftJoin(
Expand All @@ -57,9 +60,14 @@ public function findByPidsAndAuthorId($pids, int $author): array
)
)
->orderBy('sorting', 'asc')
->addOrderBy('crdate', 'desc')
->execute()->fetchAll();
->addOrderBy('crdate', 'desc');

return $rows;
if ($position !== null) {
$res->andWhere(
$queryBuilder->expr()->eq('sys_note.position', $queryBuilder->createNamedParameter($position, \PDO::PARAM_INT))
);
}

return $res->execute()->fetchAll();
}
}
19 changes: 17 additions & 2 deletions typo3/sysext/sys_note/Classes/Hook/PageHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,37 @@

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\SysNote\Controller\NoteController;
use TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository;

/**
* Hook for the page module
*/
class PageHook
{

/**
* Add sys_notes as additional content to the header of the page module
*
* @param array $params
* @param \TYPO3\CMS\Backend\Controller\PageLayoutController $parentObject
* @return string
*/
public function renderInHeader(array $params = [], \TYPO3\CMS\Backend\Controller\PageLayoutController $parentObject)
{
$controller = GeneralUtility::makeInstance(NoteController::class);
return $controller->listAction($parentObject->id, SysNoteRepository::SYS_NOTE_POSITION_TOP);
}

/**
* Add sys_notes as additional content to the footer of the page module
*
* @param array $params
* @param \TYPO3\CMS\Backend\Controller\PageLayoutController $parentObject
* @return string
*/
public function render(array $params = [], \TYPO3\CMS\Backend\Controller\PageLayoutController $parentObject)
public function renderInFooter(array $params = [], \TYPO3\CMS\Backend\Controller\PageLayoutController $parentObject)
{
$controller = GeneralUtility::makeInstance(NoteController::class);
return $controller->listAction($parentObject->id);
return $controller->listAction($parentObject->id, SysNoteRepository::SYS_NOTE_POSITION_BOTTOM);
}
}
18 changes: 16 additions & 2 deletions typo3/sysext/sys_note/Classes/Hook/RecordListHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,36 @@

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\SysNote\Controller\NoteController;
use TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository;

/**
* Hook for the list module
*/
class RecordListHook
{
/**
* Add sys_notes as additional content to the header of the list module
*
* @param array $params
* @param \TYPO3\CMS\Recordlist\RecordList $parentObject
* @return string
*/
public function renderInHeader(array $params = [], \TYPO3\CMS\Recordlist\RecordList $parentObject)
{
$controller = GeneralUtility::makeInstance(NoteController::class);
return $controller->listAction($parentObject->id, SysNoteRepository::SYS_NOTE_POSITION_TOP);
}

/**
* Add sys_notes as additional content to the footer of the list module
*
* @param array $params
* @param \TYPO3\CMS\Recordlist\RecordList $parentObject
* @return string
*/
public function render(array $params = [], \TYPO3\CMS\Recordlist\RecordList $parentObject)
public function renderInFooter(array $params = [], \TYPO3\CMS\Recordlist\RecordList $parentObject)
{
$controller = GeneralUtility::makeInstance(NoteController::class);
return $controller->listAction($parentObject->id);
return $controller->listAction($parentObject->id, SysNoteRepository::SYS_NOTE_POSITION_BOTTOM);
}
}
25 changes: 24 additions & 1 deletion typo3/sysext/sys_note/Configuration/TCA/sys_note.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,35 @@
'config' => [
'type' => 'check'
]
],
'position' => [
'label' => 'LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.position',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
[
'LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.position.top',
\TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository::SYS_NOTE_POSITION_TOP
],
[
'LLL:EXT:sys_note/Resources/Private/Language/locallang_tca.xlf:sys_note.position.bottom',
\TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository::SYS_NOTE_POSITION_BOTTOM
],
],
'default' => \TYPO3\CMS\SysNote\Domain\Repository\SysNoteRepository::SYS_NOTE_POSITION_BOTTOM,
'fieldWizard' => [
'selectIcons' => [
'disabled' => false,
],
],
]
]
],
'types' => [
'0' => ['showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
category, subject,message,
category, subject,message,position,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
personal,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
<trans-unit id="sys_note.personal">
<source>Personal:</source>
</trans-unit>
<trans-unit id="sys_note.position">
<source>Position</source>
</trans-unit>
<trans-unit id="sys_note.position.top">
<source>Top</source>
</trans-unit>
<trans-unit id="sys_note.position.bottom">
<source>Bottom</source>
</trans-unit>
</body>
</file>
</xliff>
8 changes: 5 additions & 3 deletions typo3/sysext/sys_note/ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
defined('TYPO3_MODE') or die();

// Hook into the list module
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['recordlist/Modules/Recordlist/index.php']['drawFooterHook']['sys_note'] = \TYPO3\CMS\SysNote\Hook\RecordListHook::class . '->render';
// Hook into the page module
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook']['sys_note'] = \TYPO3\CMS\SysNote\Hook\PageHook::class . '->render';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['recordlist/Modules/Recordlist/index.php']['drawHeaderHook']['sys_note'] = \TYPO3\CMS\SysNote\Hook\RecordListHook::class . '->renderInHeader';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['recordlist/Modules/Recordlist/index.php']['drawFooterHook']['sys_note'] = \TYPO3\CMS\SysNote\Hook\RecordListHook::class . '->renderInFooter';
// Hook into the page modules
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook']['sys_note'] = \TYPO3\CMS\SysNote\Hook\PageHook::class . '->renderInHeader';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook']['sys_note'] = \TYPO3\CMS\SysNote\Hook\PageHook::class . '->renderInFooter';
// Hook into the info module
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/web_info/class.tx_cms_webinfo.php']['drawFooterHook']['sys_note'] = \TYPO3\CMS\SysNote\Hook\InfoModuleHook::class . '->render';
1 change: 1 addition & 0 deletions typo3/sysext/sys_note/ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CREATE TABLE sys_note (
message text,
personal tinyint(3) unsigned DEFAULT '0' NOT NULL,
category tinyint(3) unsigned DEFAULT '0' NOT NULL,
position int(11) DEFAULT '0' NOT NULL,
sorting int(11) DEFAULT '0' NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid)
Expand Down

1 comment on commit 13260d9

@7elix
Copy link
Contributor

@7elix 7elix commented on 13260d9 Mar 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@georgringer 👍🏼 Thanks

Please sign in to comment.