Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_youtube
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_youtube
Commits
72479e3c
Commit
72479e3c
authored
4 years ago
by
Ciprian Hossu
Browse files
Options
Downloads
Patches
Plain Diff
[BUGFIX] Add condition for flexform configuration file. Add function for returning records array.
parent
880fbabf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
[FEATURE] Add backend preview for the YouTube Videos plugin
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/Hooks/PluginRenderer.php
+86
-72
86 additions, 72 deletions
Classes/Hooks/PluginRenderer.php
with
86 additions
and
72 deletions
Classes/Hooks/PluginRenderer.php
+
86
−
72
View file @
72479e3c
...
...
@@ -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
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment