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

[TASK] Create JobTeaser plugin backend preview

parent b9098756
No related branches found
No related tags found
1 merge request!24[FEATURE] Plugin Previews
......@@ -27,7 +27,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
/**
* Class PluginRenderer
* Class PluginRenderer - Renders backend previews for plugins.
*
* @package SGalinski\SgJobs\Hooks\PageLayoutView
*/
......@@ -55,7 +55,7 @@ class PluginRenderer implements \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHo
)['data']['sDEF']['lDEF'];
$templateData = [
'redirectPage' => $this->addTitlesToRecordIdList(
'redirectPage' => $this->addFieldContentsToRecordIdList(
'pages', $pluginConfiguration['settings.redirectPage']['vDEF']
),
'privacyPolicyPage' => $pluginConfiguration['settings.privacyPolicyPage']['vDEF']
......@@ -82,12 +82,12 @@ class PluginRenderer implements \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHo
$filterByExperienceLevel = $pluginConfiguration['settings.filterByExperienceLevel']['vDEF'] ?: '';
$templateData = [
'applyPage' => $this->addTitlesToRecordIdList(
'applyPage' => $this->addFieldContentsToRecordIdList(
'pages', $pluginConfiguration['settings.applyPage']['vDEF']
),
'jobLimit' => $pluginConfiguration['settings.jobLimit']['vDEF'],
'orderBy' => $pluginConfiguration['settings.orderBy']['vDEF'],
'filterByExperienceLevel' => $this->addTitlesToRecordIdList(
'filterByExperienceLevel' => $this->addFieldContentsToRecordIdList(
'tx_sgjobs_domain_model_experience_level', $filterByExperienceLevel
)
];
......@@ -96,12 +96,42 @@ class PluginRenderer implements \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHo
// Also assign the standard plugin settings to the template
// as they are actually used in the corresponding controller action.
$view->assign('storagePages', $this->addTitlesToRecordIdList('pages', $row['pages']));
$view->assign('storagePages', $this->addFieldContentsToRecordIdList('pages', $row['pages']));
$view->assign('recursive', $row['recursive']);
$itemContent .= $view->render();
break;
case 'sgjobs_jobteaser':
$drawItem = FALSE;
$view = $this->createViewWithTemplate('JobTeaser');
$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']['sDEF']['lDEF'];
$templateData = [
'offersPage' => $this->addFieldContentsToRecordIdList(
'pages', $pluginConfiguration['settings.offersPage']['vDEF']
),
'applyPage' => $this->addFieldContentsToRecordIdList(
'pages', $pluginConfiguration['settings.applyPage']['vDEF']
),
'locations' => $this->addFieldContentsToRecordIdList(
'tx_sgjobs_domain_model_company', $pluginConfiguration['settings.locations']['vDEF'], 'name'
),
];
$view->assign('data', $templateData);
$itemContent .= $view->render();
break;
default:
// No need to do anything
}
......@@ -162,23 +192,26 @@ class PluginRenderer implements \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHo
}
/**
* Takes a comma-separated list of record IDs and the corresponding table.
* Returns another comma-space-separated list of the same records with the titles added.
* 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 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}
<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_jobs/Resources/Private/Language/locallang_db.xlf:tx_sgjobs_domain_model_job.offers_page"/>
</th>
<td>
{data.offersPage}
</td>
</tr>
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_jobs/Resources/Private/Language/locallang_db.xlf:tx_sgjobs_domain_model_job.application_form_page"/>
</th>
<td>
{data.applyPage}
</td>
</tr>
<tr>
<th scope="row">
<f:translate
key="LLL:EXT:sg_jobs/Resources/Private/Language/locallang_db.xlf:tx_sgjobs_domain_model_job.teaser_locations"/>
</th>
<td>
{data.locations}
</td>
</tr>
</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