Skip to content
Snippets Groups Projects
Commit 72479e3c authored by Ciprian Hossu's avatar Ciprian Hossu
Browse files

[BUGFIX] Add condition for flexform configuration file. Add function for returning records array.

parent 880fbabf
No related branches found
No related tags found
1 merge request!1[FEATURE] Add backend preview for the YouTube Videos plugin
......@@ -35,6 +35,25 @@ use TYPO3\CMS\Form\Service\TranslationService;
* @package SGalinski\SgYoutube\Hooks
*/
class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
/**
* Return an array of pages or categories, with their respective ids
*
* @param $recodIds
* @return array $records
*/
public function buildRecordArray($table, $recodIds) {
$backendUtilityObject = GeneralUtility::makeInstance(BackendUtility::class);
$recordsArray = explode(',', $recodIds);
$records = [];
foreach ($recordsArray as $i => $recordId) {
$records[] = $backendUtilityObject->getRecord(
$table, $recordId, 'title'
)['title'] . ' ' . '(' . $recordId . ')';
}
return $records;
}
/**
* Preprocesses the preview rendering of a content element of type "sg_youtube"
*
......@@ -48,6 +67,8 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row) {
if ($row['list_type'] === 'sgyoutube_youtube') {
$drawItem = FALSE;
// Content element labels
$labelPluginName = BackendUtility::getLabelFromItemListMerged(
$row['pid'], 'tt_content', 'list_type', $row['list_type']
......@@ -86,88 +107,81 @@ class PluginRenderer implements PageLayoutViewDrawItemHookInterface {
// Get the FlexForm configuration file
$xmlFilePath = $GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds']['sgyoutube_youtube,list'];
$xmlContent = GeneralUtility::getFileAbsFileName(
str_replace(
'FILE:EXT:', 'EXT:', $xmlFilePath
)
);
// Get contents of the FlexForm configuration file
$xmlString = file_get_contents($xmlContent);
$configurationArray = GeneralUtility::xml2array($xmlString);
// Begin rendering of table
$itemContent .= '<br>' . '<table class="table table-striped">';
// Table header
$labelSettings = 'LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:settings';
$labelvalue = 'LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:values';
$itemContent .= '<row>' . '<th style="width: 50%">' . $translationServiceObject->translate(
$labelSettings
) . '</th>';
$itemContent .= '<th style="width: 50%">' . $translationServiceObject->translate(
$labelvalue
) . '</th>' . '</tr>';
// Loop through plugin options and render rows
foreach ($pluginOptions['data']['sDEF']['lDEF'] as $key => $setting) {
// if plugin option exists within the Flexform configuration file
if (array_key_exists($key, $configurationArray['sheets']['sDEF']['ROOT']['el'])) {
// Display label
$labelId = $configurationArray['sheets']['sDEF']['ROOT']['el'][$key]['TCEforms']['label'];
$itemContent .= '<row>' . '<td><strong>' . $translationServiceObject->translate(
trim($labelId)
) . '</strong></td>';
// Display value
// Show different icon for the 'Show API Result' field, depending on checkbox value
if ($key === 'settings.showApiResult') {
if ($setting['vDEF'] === '0') {
$itemContent .= '<td>' . GeneralUtility::makeInstance(IconFactory::class)->getIcon(
'actions-close', Icon::SIZE_SMALL
)
->render('inline') . '</td>' . '</tr>';
if ($xmlFilePath !== '') {
$xmlContent = GeneralUtility::getFileAbsFileName(
str_replace(
'FILE:EXT:', 'EXT:', $xmlFilePath
)
);
// Get contents of the FlexForm configuration file
$xmlString = file_get_contents($xmlContent);
$configurationArray = GeneralUtility::xml2array($xmlString);
// Begin rendering of table
$itemContent .= '<br>' . '<table class="table table-striped">';
// Table header
$labelSettings = 'LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:settings';
$labelvalue = 'LLL:EXT:sg_youtube/Resources/Private/Language/locallang.xlf:values';
$itemContent .= '<row>' . '<th style="width: 50%">' . $translationServiceObject->translate(
$labelSettings
) . '</th>';
$itemContent .= '<th style="width: 50%">' . $translationServiceObject->translate(
$labelvalue
) . '</th>' . '</tr>';
// Loop through plugin options and render rows
foreach ($pluginOptions['data']['sDEF']['lDEF'] as $key => $setting) {
// if plugin option exists within the Flexform configuration file
if (array_key_exists($key, $configurationArray['sheets']['sDEF']['ROOT']['el'])) {
// Display label
$labelId = $configurationArray['sheets']['sDEF']['ROOT']['el'][$key]['TCEforms']['label'];
$itemContent .= '<row>' . '<td><strong>' . $translationServiceObject->translate(
trim($labelId)
) . '</strong></td>';
// Display value
// Show different icon for the 'Show API Result' field, depending on checkbox value
if ($key === 'settings.showApiResult') {
if ($setting['vDEF'] === '0') {
$itemContent .= '<td>' . GeneralUtility::makeInstance(IconFactory::class)->getIcon(
'actions-close', Icon::SIZE_SMALL
)
->render('inline') . '</td>' . '</tr>';
} else {
$itemContent .= '<td>' . GeneralUtility::makeInstance(IconFactory::class)->getIcon(
'actions-check', Icon::SIZE_SMALL
)
->render('inline') . '</td>' . '</tr>';
}
// Remaining values
} else {
$itemContent .= '<td>' . GeneralUtility::makeInstance(IconFactory::class)->getIcon(
'actions-check', Icon::SIZE_SMALL
)
->render('inline') . '</td>' . '</tr>';
$itemContent .= '<td>' . $setting['vDEF'] . '</td>' . '</tr>';
}
// Remaining values
} else {
$itemContent .= '<td>' . $setting['vDEF'] . '</td>' . '</tr>';
}
}
}
// Record Storage
if ($row['pages'] !== '') {
// Record Storage Page label
$labelRecordStorage = 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:pages.ALT.list_formlabel';
// Record Storage
if ($row['pages'] !== '') {
// Record Storage Page label
$labelRecordStorage = 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:pages.ALT.list_formlabel';
// Get storage page(s)
$backendUtilityObject = GeneralUtility::makeInstance(BackendUtility::class);
$storagePageIds = explode(',', $row['pages']);
$storagePages = array();
foreach ($storagePageIds as $i => $storagePageId) {
$storagePages[] = $backendUtilityObject->getRecord(
'pages', $storagePageId, 'title'
)['title'] . ' ' . '(' . $storagePageId . ')';
// Render 'Record Storage Page' row
$itemContent .= '<row>' . '<td><strong>' . $translationServiceObject->translate(
$labelRecordStorage
) . '</strong></td>';
$itemContent .= '<td>' . implode(
', ', $this->buildRecordArray('pages', $row['pages'])
) . '</td>' . '</tr>';
}
// Render 'Record Storage Page' row
$itemContent .= '<row>' . '<td><strong>' . $translationServiceObject->translate(
$labelRecordStorage
) . '</strong></td>';
$itemContent .= '<td>' . implode(', ', $storagePages) . '</td>' . '</tr>';
// End rendering of table
$itemContent .= '</table>';
}
// End rendering of table
$itemContent .= '</table>';
$drawItem = FALSE;
}
}
}
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