Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
TYPO3
df_tabs
Commits
d5bad4dd
Commit
d5bad4dd
authored
Feb 14, 2022
by
Matthias Adrowski
Browse files
[TASK] Update Previews + PreviewServices
parent
4fb3e933
Changes
3
Hide whitespace changes
Inline
Side-by-side
Classes/Hooks/PageLayoutView/PluginRenderer.php
View file @
d5bad4dd
...
...
@@ -20,6 +20,7 @@ namespace SGalinski\DfTabs\Hooks\PageLayoutView;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use
SGalinski\DfTabs\Preview\PreviewService
;
use
TYPO3\CMS\Backend\Utility\BackendUtility
;
use
TYPO3\CMS\Backend\View\PageLayoutView
;
use
TYPO3\CMS\Core\Localization\LanguageService
;
...
...
@@ -32,6 +33,14 @@ use TYPO3\CMS\Fluid\View\StandaloneView;
* @package SGalinski\DfTabs\Hooks\PageLayoutView
*/
class
PluginRenderer
implements
\
TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface
{
protected
PreviewService
$previewService
;
public
function
init
()
{
$this
->
previewService
=
GeneralUtility
::
makeInstance
(
PreviewService
::
class
);
}
/**
* @inheritDoc
* @noinspection ReferencingObjectsInspection
...
...
@@ -43,68 +52,13 @@ class PluginRenderer implements \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHo
&
$itemContent
,
array
&
$row
)
:
void
{
$this
->
init
();
if
(
$row
[
'list_type'
]
===
'df_tabs_plugin1'
)
{
$drawItem
=
FALSE
;
$view
=
GeneralUtility
::
makeInstance
(
StandaloneView
::
class
);
$view
->
setPartialRootPaths
([
'EXT:df_tabs/Resources/Private/Partials/Backend'
]);
$view
->
setTemplateRootPaths
([
'EXT:df_tabs/Resources/Private/Templates/Backend'
]);
$view
->
setTemplate
(
'Tabs.html'
);
$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'
];
$tabElements
=
GeneralUtility
::
trimExplode
(
','
,
$pluginConfiguration
[
'data'
][
'vDEF'
],
TRUE
);
$tabs
=
[];
foreach
(
$tabElements
as
$tabElement
)
{
// Each $tabElement is either 'pages_<id>' or 'tt_content_<id>'.
$recordTable
=
substr
(
$tabElement
,
0
,
strrpos
(
$tabElement
,
'_'
));
$recordId
=
substr
(
$tabElement
,
strrpos
(
$tabElement
,
'_'
)
+
1
);
if
(
$recordTable
===
'pages'
)
{
$recordTitle
=
BackendUtility
::
getRecord
(
$recordTable
,
$recordId
,
'title'
)[
'title'
];
$recordType
=
'page'
;
}
elseif
(
$recordTable
===
'tt_content'
)
{
$recordTitle
=
BackendUtility
::
getRecord
(
$recordTable
,
$recordId
,
'header'
)[
'header'
];
$recordType
=
'content'
;
}
else
{
$recordTitle
=
$tabElement
;
$recordType
=
'unknown'
;
}
$tabs
[]
=
[
'type'
=>
$recordType
,
'title'
=>
$recordTitle
,
'uid'
=>
$recordId
];
}
$titles
=
GeneralUtility
::
trimExplode
(
"
\n
"
,
$pluginConfiguration
[
'titles'
][
'vDEF'
]);
// Remove first item if it is empty to mimic what is actually saved to the DB and frontend behaviour.
// This gets done automatically on a second save of the plugin anyways but it should happen every time.
if
(
$titles
[
0
]
===
''
)
{
array_shift
(
$titles
);
}
$templateData
=
[
'mode'
=>
$pluginConfiguration
[
'mode'
][
'vDEF'
],
'tabs'
=>
$tabs
,
'titles'
=>
$titles
,
'enableAutoPlay'
=>
$pluginConfiguration
[
'enableAutoPlay'
][
'vDEF'
],
'autoPlayInterval'
=>
$pluginConfiguration
[
'autoPlayInterval'
][
'vDEF'
],
'enableMouseOver'
=>
$pluginConfiguration
[
'enableMouseOver'
][
'vDEF'
],
'hashName'
=>
$pluginConfiguration
[
'hashName'
][
'vDEF'
]
];
$view
->
assign
(
'data'
,
$templateData
);
$view
=
$this
->
previewService
->
getPluginView
(
$row
);
$itemContent
.
=
$view
->
render
();
}
...
...
Classes/Preview/PreviewRenderer.php
View file @
d5bad4dd
...
...
@@ -39,8 +39,11 @@ class PreviewRenderer implements PreviewRendererInterface {
*/
protected
LanguageService
$languageService
;
public
function
__construct
(
LanguageService
$languageService
)
{
protected
PreviewService
$previewService
;
public
function
__construct
(
LanguageService
$languageService
,
PreviewService
$previewService
)
{
$this
->
languageService
=
$languageService
;
$this
->
previewService
=
$previewService
;
}
/**
...
...
@@ -69,87 +72,9 @@ class PreviewRenderer implements PreviewRendererInterface {
* @return string
*/
public
function
renderPageModulePreviewContent
(
GridColumnItem
$item
):
string
{
$view
=
GeneralUtility
::
makeInstance
(
StandaloneView
::
class
);
$view
->
setPartialRootPaths
([
'EXT:df_tabs/Resources/Private/Partials/Backend'
]);
$view
->
setTemplateRootPaths
([
'EXT:df_tabs/Resources/Private/Templates/Backend'
]);
$view
->
setTemplate
(
'Tabs.html'
);
$view
->
assign
(
'uid'
,
$item
->
getRecord
()[
'uid'
]);
// Get available plugin settings and their values from flexform
$templateData
=
[];
// Get available plugin settings and their values from flexform
$pluginConfiguration
=
GeneralUtility
::
xml2array
(
$item
->
getRecord
()[
'pi_flexform'
],
'T3DataStructure'
)[
'data'
][
'sDEF'
][
'lDEF'
];
$tabElements
=
GeneralUtility
::
trimExplode
(
','
,
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'data'
),
TRUE
);
$tabs
=
[];
foreach
(
$tabElements
as
$tabElement
)
{
// Each $tabElement is either 'pages_<id>' or 'tt_content_<id>'.
$recordTable
=
substr
(
$tabElement
,
0
,
strrpos
(
$tabElement
,
'_'
));
$recordId
=
substr
(
$tabElement
,
strrpos
(
$tabElement
,
'_'
)
+
1
);
if
(
$recordTable
===
'pages'
)
{
$recordTitle
=
BackendUtility
::
getRecord
(
$recordTable
,
$recordId
,
'title'
)[
'title'
];
$recordType
=
'page'
;
}
elseif
(
$recordTable
===
'tt_content'
)
{
$recordTitle
=
BackendUtility
::
getRecord
(
$recordTable
,
$recordId
,
'header'
)[
'header'
];
$recordType
=
'content'
;
}
else
{
$recordTitle
=
$tabElement
;
$recordType
=
'unknown'
;
}
$tabs
[]
=
[
'type'
=>
$recordType
,
'title'
=>
$recordTitle
,
'uid'
=>
$recordId
];
}
$titles
=
GeneralUtility
::
trimExplode
(
"
\n
"
,
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'titles'
));
// Remove first item if it is empty to mimic what is actually saved to the DB and frontend behaviour.
// This gets done automatically on a second save of the plugin anyways but it should happen every time.
if
(
$titles
[
0
]
===
''
)
{
array_shift
(
$titles
);
}
$templateData
=
[
'mode'
=>
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'mode'
),
'tabs'
=>
$tabs
,
'titles'
=>
$titles
,
'enableAutoPlay'
=>
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'enableAutoPlay'
),
'autoPlayInterval'
=>
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'autoPlayInterval'
),
'enableMouseOver'
=>
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'enableMouseOver'
),
'hashName'
=>
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'hashName'
)
];
$view
->
assign
(
'data'
,
$templateData
);
return
$view
->
render
();
return
$this
->
previewService
->
getPluginView
(
$item
->
getRecord
())
->
render
();
}
/**
* @param array $conf
* @param string $key
* @param string $returnType
* @return array|mixed|string
*/
private
function
passVDefOnKeyToTemplate
(
array
$conf
,
string
$key
,
string
$returnType
=
''
)
{
if
(
isset
(
$conf
[
$key
]))
{
return
$conf
[
$key
][
'vDEF'
];
}
// check if we got a possible returntype:
if
(
$returnType
===
self
::
RETURNTYPE_ARR
)
{
return
[];
}
return
''
;
}
/**
* Render a footer for the record to display in page module below
...
...
Classes/Preview/PreviewService.php
0 → 100644
View file @
d5bad4dd
<?php
/***************************************************************
* Copyright notice
* (c) sgalinski Internet Services (https://www.sgalinski.de)
* All rights reserved
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
namespace
SGalinski\DfTabs\Preview
;
use
TYPO3\CMS\Backend\Utility\BackendUtility
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Fluid\View\StandaloneView
;
/**
* small helper class, aslong as we use PageLayout hook + Previewrenderer....
*/
class
PreviewService
{
public
const
RETURNTYPE_ARR
=
'array'
;
public
function
getPluginView
(
array
$row
):
StandaloneView
{
$view
=
GeneralUtility
::
makeInstance
(
StandaloneView
::
class
);
$view
->
setPartialRootPaths
([
'EXT:df_tabs/Resources/Private/Partials/Backend'
]);
$view
->
setTemplateRootPaths
([
'EXT:df_tabs/Resources/Private/Templates/Backend'
]);
$view
->
setTemplate
(
'Tabs.html'
);
$view
->
assign
(
'uid'
,
$row
[
'uid'
]);
// Get available plugin settings and their values from flexform
$templateData
=
[];
// Get available plugin settings and their values from flexform
$pluginConfiguration
=
GeneralUtility
::
xml2array
(
$row
[
'pi_flexform'
],
'T3DataStructure'
)[
'data'
][
'sDEF'
][
'lDEF'
];
$tabElements
=
GeneralUtility
::
trimExplode
(
','
,
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'data'
),
TRUE
);
$tabs
=
[];
foreach
(
$tabElements
as
$tabElement
)
{
// Each $tabElement is either 'pages_<id>' or 'tt_content_<id>'.
$recordTable
=
substr
(
$tabElement
,
0
,
strrpos
(
$tabElement
,
'_'
));
$recordId
=
substr
(
$tabElement
,
strrpos
(
$tabElement
,
'_'
)
+
1
);
if
(
$recordTable
===
'pages'
)
{
$recordTitle
=
BackendUtility
::
getRecord
(
$recordTable
,
$recordId
,
'title'
)[
'title'
];
$recordType
=
'page'
;
}
elseif
(
$recordTable
===
'tt_content'
)
{
$recordTitle
=
BackendUtility
::
getRecord
(
$recordTable
,
$recordId
,
'header'
)[
'header'
];
$recordType
=
'content'
;
}
else
{
$recordTitle
=
$tabElement
;
$recordType
=
'unknown'
;
}
$tabs
[]
=
[
'type'
=>
$recordType
,
'title'
=>
$recordTitle
,
'uid'
=>
$recordId
];
}
$titles
=
GeneralUtility
::
trimExplode
(
"
\n
"
,
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'titles'
));
// Remove first item if it is empty to mimic what is actually saved to the DB and frontend behaviour.
// This gets done automatically on a second save of the plugin anyways but it should happen every time.
if
(
$titles
[
0
]
===
''
)
{
array_shift
(
$titles
);
}
$templateData
=
[
'mode'
=>
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'mode'
),
'tabs'
=>
$tabs
,
'titles'
=>
$titles
,
'enableAutoPlay'
=>
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'enableAutoPlay'
),
'autoPlayInterval'
=>
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'autoPlayInterval'
),
'enableMouseOver'
=>
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'enableMouseOver'
),
'hashName'
=>
$this
->
passVDefOnKeyToTemplate
(
$pluginConfiguration
,
'hashName'
)
];
$view
->
assign
(
'data'
,
$templateData
);
return
$view
;
}
/**
* @param array $conf
* @param string $key
* @param string $returnType
* @return array|mixed|string
*/
private
function
passVDefOnKeyToTemplate
(
array
$conf
,
string
$key
,
string
$returnType
=
''
)
{
if
(
isset
(
$conf
[
$key
]))
{
return
$conf
[
$key
][
'vDEF'
];
}
// check if we got a possible returntype:
if
(
$returnType
===
self
::
RETURNTYPE_ARR
)
{
return
[];
}
return
''
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment