Skip to content
Snippets Groups Projects
Commit 11e27034 authored by Tim Wagner's avatar Tim Wagner
Browse files

[TASK] Create backend preview for newsByAuthor news plugin

parent 501cf505
No related branches found
No related tags found
1 merge request!24[FEATURE] Plugin Backend Previews
......@@ -92,10 +92,10 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
$templateData = [
'limit' => $pluginConfiguration['settings.limit']['vDEF'],
'categories' => $this->addTitlesToRecordIdList(
'pages',$pluginConfiguration['settings.categories']['vDEF'] ?? ''
'categories' => $this->addFieldContentsToRecordIdList(
'pages', $pluginConfiguration['settings.categories']['vDEF'] ?? ''
),
'tags' => $this->addTitlesToRecordIdList(
'tags' => $this->addFieldContentsToRecordIdList(
'sys_category', $pluginConfiguration['settings.tags']['vDEF'] ?? ''
),
'starttime' => $pluginConfiguration['settings.starttime']['vDEF'],
......@@ -123,10 +123,10 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
$templateData = [
'newsLimitPerPage' => $pluginConfiguration['settings.newsLimitPerPage']['vDEF'],
'categories' => $this->addTitlesToRecordIdList(
'pages',$pluginConfiguration['settings.categories']['vDEF']
'categories' => $this->addFieldContentsToRecordIdList(
'pages', $pluginConfiguration['settings.categories']['vDEF']
),
'tags' => $this->addTitlesToRecordIdList(
'tags' => $this->addFieldContentsToRecordIdList(
'sys_category', $pluginConfiguration['settings.tags']['vDEF']
),
'starttime' => $pluginConfiguration['settings.starttime']['vDEF'],
......@@ -140,6 +140,45 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
$itemContent .= $view->render();
break;
case 'sgnews_newsbyauthor':
$drawItem = FALSE;
$view = $this->createViewWithTemplate('NewsByAuthor');
$view->assign('uid', $row['uid']);
$this->adaptPluginHeaderContent($headerContent, $row);
// Get available plugin settings and their values from flexform
$pluginConfiguration = GeneralUtility::xml2array(
$row['pi_flexform'], 'T3DataStructure'
)['data']['main']['lDEF'];
$templateData = [
'showDetails' => $pluginConfiguration['settings.showDetails']['vDEF'],
'newsAuthors' => $this->addFieldContentsToRecordIdList(
'tx_sgnews_domain_model_author',
$pluginConfiguration['settings.newsAuthors']['vDEF'],
'name'
)
];
$backendUtility = GeneralUtility::makeInstance(BackendUtility::class);
$excludedNewsIds = GeneralUtility::intExplode(
',', $pluginConfiguration['settings.excludedNews']['vDEF'], TRUE
);
$excludedNewsListWithTitles = [];
foreach ($excludedNewsIds as $excludedNewsId) {
$excludedNewsListWithTitles[] = $backendUtility::getRecord(
'pages', $excludedNewsId, 'title'
)['title'] . ' [' . $excludedNewsId . ']';
}
$templateData['excludedNews'] = $excludedNewsListWithTitles;
$view->assign('data', $templateData);
$itemContent .= $view->render();
break;
default:
// No need to do anything
}
......@@ -153,9 +192,7 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
* @return StandaloneView
*/
protected
function createViewWithTemplate(
string $templateName
): StandaloneView {
function createViewWithTemplate(string $templateName): StandaloneView {
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplateRootPaths(['EXT:sg_news/Resources/Private/Templates/Backend']);
$view->setPartialRootPaths(['EXT:sg_news/Resources/Private/Partials/Backend']);
......@@ -201,23 +238,26 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
}
/**
* Takes a comma-separated list of record IDs and the corresponding table.
* Returns another comma-space-separated list of the same records with the record titles added.
* The returned list looks nice enough to be rendered in the backend preview directly.
* Takes a comma-separated list of record IDs, the corresponding table and optionally the field to look up.
* Returns another comma-space-separated list of the same records with the content of the field added.
* The returned list should look nice enough to be rendered in the backend preview directly.
*
* @param $table
* @param $recordIdList
* @param string $table
* @param string $recordIdList
* @param string $field
* @return string
*/
protected function addTitlesToRecordIdList(string $table, string $recordIdList): string {
protected function addFieldContentsToRecordIdList(
string $table, string $recordIdList, string $field = 'title'
): string {
$backendUtility = GeneralUtility::makeInstance(BackendUtility::class);
$recordIdsArray = GeneralUtility::intExplode(',', $recordIdList, TRUE);
$recordsWithTitlesArray = [];
foreach ($recordIdsArray as $recordId) {
$recordsWithTitlesArray[] = $backendUtility::getRecord(
$table, $recordId, 'title'
)['title'] . ' [' . $recordId . ']';
$table, $recordId, $field
)[$field] . ' [' . $recordId . ']';
}
return implode(', ', $recordsWithTitlesArray);
}
......
{namespace be=TYPO3\CMS\Backend\ViewHelpers}
{namespace core=TYPO3\CMS\Core\ViewHelpers}
<be:link.editRecord table="tt_content" uid="{uid}">
<br/>
<table class="table table-striped table-bordered">
<f:render partial="PluginDataTableHeader"/>
<tbody>
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.showDetails"/>
</th>
<td>
<f:if condition="{data.showDetails}">
<f:then>
<core:icon alternativeMarkupIdentifier="inline" identifier="actions-check"/>
</f:then>
<f:else>
<core:icon alternativeMarkupIdentifier="inline" identifier="actions-close"/>
</f:else>
</f:if>
</td>
</tr>
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.newsAuthor"/>
</th>
<td>
{data.newsAuthors}
</td>
</tr>
<f:if condition="{data.excludedNews}">
<tr>
<th scope="row" rowspan="0">
<f:translate
key="LLL:EXT:sg_news/Resources/Private/Language/locallang_db.xlf:plugin.flexForm.excludedNews"/>
</th>
</tr>
<f:for each="{data.excludedNews}" as="excludedNews">
<tr>
<td>
{excludedNews}
</td>
</tr>
</f:for>
</f:if>
</tbody>
</table>
</be:link.editRecord>
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