Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_jobs
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
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_jobs
Commits
c8add3b6
Commit
c8add3b6
authored
3 years ago
by
Matthias Adrowski
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Add new PreviewRenderer
parent
d1b439bb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!35
Feature upgrade to typo3 11
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Classes/Preview/PreviewRenderer.php
+230
-0
230 additions, 0 deletions
Classes/Preview/PreviewRenderer.php
Configuration/Services.yaml
+3
-0
3 additions, 0 deletions
Configuration/Services.yaml
Configuration/TCA/Overrides/tt_content.php
+4
-0
4 additions, 0 deletions
Configuration/TCA/Overrides/tt_content.php
with
237 additions
and
0 deletions
Classes/Preview/PreviewRenderer.php
0 → 100644
+
230
−
0
View file @
c8add3b6
<?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\SgJobs\Preview
;
use
TYPO3\CMS\Backend\Preview\PreviewRendererInterface
;
use
TYPO3\CMS\Backend\Utility\BackendUtility
;
use
TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem
;
use
TYPO3\CMS\Core\Localization\LanguageService
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Fluid\View\StandaloneView
;
/**
*
*/
class
PreviewRenderer
implements
PreviewRendererInterface
{
/**
* @var LanguageService $languageService
*/
protected
LanguageService
$languageService
;
public
function
__construct
(
LanguageService
$languageService
)
{
$this
->
languageService
=
$languageService
;
}
/**
* Dedicated method for rendering preview header HTML for
* the page module only. Receives $item which is an instance of
* GridColumnItem which has a getter method to return the record.
*
* @param GridColumnItem $item
* @return string
*/
public
function
renderPageModulePreviewHeader
(
GridColumnItem
$item
):
string
{
$label
=
BackendUtility
::
getLabelFromItemListMerged
(
$item
->
getRecord
()[
'pid'
],
'tt_content'
,
'list_type'
,
$item
->
getRecord
()[
'list_type'
]
);
return
'<h4><span class="label label-primary">'
.
$this
->
languageService
->
sL
(
$label
)
.
'</span> </h4>'
;
}
/**
* Dedicated method for rendering preview body HTML for
* the page module only.
*
* @param GridColumnItem $item
* @return string
*/
public
function
renderPageModulePreviewContent
(
GridColumnItem
$item
):
string
{
$row
=
$item
->
getRecord
();
switch
(
$row
[
'list_type'
])
{
case
'sgjobs_jobapplication'
:
$drawItem
=
FALSE
;
$view
=
$this
->
createViewWithTemplate
(
'JobApplication'
);
$view
->
assign
(
'uid'
,
$row
[
'uid'
]);
// Get available plugin settings and their values from flexform
$pluginConfiguration
=
GeneralUtility
::
xml2array
(
$row
[
'pi_flexform'
],
'T3DataStructure'
)[
'data'
][
'sDEF'
][
'lDEF'
];
$redirectPage
=
$pluginConfiguration
[
'settings.redirectPage'
][
'vDEF'
];
$templateData
=
[
'redirectPage'
=>
is_string
(
$redirectPage
)
?
$this
->
addFieldContentsToRecordIdList
(
'pages'
,
$redirectPage
)
:
''
,
'privacyPolicyPage'
=>
$pluginConfiguration
[
'settings.privacyPolicyPage'
][
'vDEF'
]
];
$view
->
assign
(
'data'
,
$templateData
);
break
;
case
'sgjobs_joblist'
:
$drawItem
=
FALSE
;
$view
=
$this
->
createViewWithTemplate
(
'Joblist'
);
$view
->
assign
(
'uid'
,
$row
[
'uid'
]);
// Get available plugin settings and their values from flexform
$pluginConfiguration
=
GeneralUtility
::
xml2array
(
$row
[
'pi_flexform'
],
'T3DataStructure'
)[
'data'
][
'sDEF'
][
'lDEF'
];
$applyPage
=
$pluginConfiguration
[
'settings.applyPage'
][
'vDEF'
];
$filterByExperienceLevel
=
$pluginConfiguration
[
'settings.filterByExperienceLevel'
][
'vDEF'
];
$templateData
=
[
'applyPage'
=>
is_string
(
$applyPage
)
?
$this
->
addFieldContentsToRecordIdList
(
'pages'
,
$applyPage
)
:
''
,
'jobLimit'
=>
$pluginConfiguration
[
'settings.jobLimit'
][
'vDEF'
],
'orderBy'
=>
$pluginConfiguration
[
'settings.orderBy'
][
'vDEF'
],
'filterByExperienceLevel'
=>
is_string
(
$filterByExperienceLevel
)
?
$this
->
addFieldContentsToRecordIdList
(
'tx_sgjobs_domain_model_experience_level'
,
$filterByExperienceLevel
)
:
''
];
$view
->
assign
(
'data'
,
$templateData
);
// Also assign the standard plugin settings to the template
// as they are actually used in the corresponding controller action.
$view
->
assign
(
'storagePages'
,
is_string
(
$row
[
'pages'
])
?
$this
->
addFieldContentsToRecordIdList
(
'pages'
,
$row
[
'pages'
]
)
:
''
);
$view
->
assign
(
'recursive'
,
$row
[
'recursive'
]);
break
;
case
'sgjobs_jobteaser'
:
$drawItem
=
FALSE
;
$view
=
$this
->
createViewWithTemplate
(
'JobTeaser'
);
$view
->
assign
(
'uid'
,
$row
[
'uid'
]);
// Get available plugin settings and their values from flexform
$pluginConfiguration
=
GeneralUtility
::
xml2array
(
$row
[
'pi_flexform'
],
'T3DataStructure'
)[
'data'
][
'sDEF'
][
'lDEF'
];
$offersPage
=
$pluginConfiguration
[
'settings.offersPage'
][
'vDEF'
];
$applyPage
=
$pluginConfiguration
[
'settings.applyPage'
][
'vDEF'
];
$locations
=
$pluginConfiguration
[
'settings.locations'
][
'vDEF'
];
$templateData
=
[
'offersPage'
=>
is_string
(
$offersPage
)
?
$this
->
addFieldContentsToRecordIdList
(
'pages'
,
$offersPage
)
:
''
,
'applyPage'
=>
is_string
(
$applyPage
)
?
$this
->
addFieldContentsToRecordIdList
(
'pages'
,
$applyPage
)
:
''
,
'locations'
=>
is_string
(
$locations
)
?
$this
->
addFieldContentsToRecordIdList
(
'tx_sgjobs_domain_model_company'
,
$locations
,
'name'
)
:
''
,
];
$view
->
assign
(
'data'
,
$templateData
);
break
;
default
:
// No need to do anything
}
return
$view
->
render
();
}
/**
* Render a footer for the record to display in page module below
* the body of the item's preview.
*
* @param GridColumnItem $item
* @return string
*/
public
function
renderPageModulePreviewFooter
(
GridColumnItem
$item
):
string
{
return
''
;
}
/**
* Dedicated method for wrapping a preview header and body HTML.
*
* @param string $previewHeader
* @param string $previewContent
* @param GridColumnItem $item
* @return string
*/
public
function
wrapPageModulePreview
(
string
$previewHeader
,
string
$previewContent
,
GridColumnItem
$item
):
string
{
return
$previewHeader
.
$previewContent
;
}
/**
* Creates a new StandaloneView object with template and partial root paths,
* attaches the template with the given name to it and returns it.
*
* @param string $templateName
* @return StandaloneView
*/
protected
function
createViewWithTemplate
(
string
$templateName
):
StandaloneView
{
$view
=
GeneralUtility
::
makeInstance
(
StandaloneView
::
class
);
$view
->
setTemplateRootPaths
([
'EXT:sg_jobs/Resources/Private/Templates/Backend'
]);
$view
->
setPartialRootPaths
([
'EXT:sg_jobs/Resources/Private/Partials/Backend'
]);
if
(
!
str_ends_with
(
$templateName
,
'.html'
))
{
$templateName
.
=
'.html'
;
}
$view
->
setTemplate
(
$templateName
);
return
$view
;
}
/**
* 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
addFieldContentsToRecordIdList
(
string
$table
,
string
$recordIdList
,
string
$field
=
'title'
):
string
{
$recordIdsArray
=
GeneralUtility
::
intExplode
(
','
,
$recordIdList
,
TRUE
);
$recordsWithTitlesArray
=
[];
foreach
(
$recordIdsArray
as
$recordId
)
{
$recordsWithTitlesArray
[]
=
BackendUtility
::
getRecord
(
$table
,
$recordId
,
$field
)[
$field
]
.
' ['
.
$recordId
.
']'
;
}
return
implode
(
', '
,
$recordsWithTitlesArray
);
}
}
This diff is collapsed.
Click to expand it.
Configuration/Services.yaml
+
3
−
0
View file @
c8add3b6
...
...
@@ -13,6 +13,9 @@ services:
SGalinski\SgJobs\Service\BackendService
:
public
:
true
SGalinski\SgJobs\Preview\PreviewRenderer
:
public
:
true
SGalinski\SgJobs\Event\Listener\AccessPageListEventListener
:
tags
:
-
name
:
event.listener
...
...
This diff is collapsed.
Click to expand it.
Configuration/TCA/Overrides/tt_content.php
+
4
−
0
View file @
c8add3b6
...
...
@@ -59,3 +59,7 @@ $GLOBALS['TCA']['tt_content']['types']['list']['subtypes_addlist']['sgjobs_jobte
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::
addPiFlexFormValue
(
'sgjobs_jobteaser'
,
'FILE:EXT:sg_jobs/Configuration/FlexForms/JobTeaser.xml'
);
$GLOBALS
[
'TCA'
][
'tt_content'
][
'types'
][
'list'
][
'previewRenderer'
][
'sgjobs_joblist'
]
=
\SGalinski\SgJobs\Preview\PreviewRenderer
::
class
;
$GLOBALS
[
'TCA'
][
'tt_content'
][
'types'
][
'list'
][
'previewRenderer'
][
'sgjobs_jobapplication'
]
=
\SGalinski\SgJobs\Preview\PreviewRenderer
::
class
;
$GLOBALS
[
'TCA'
][
'tt_content'
][
'types'
][
'list'
][
'previewRenderer'
][
'sgjobs_jobteaser'
]
=
\SGalinski\SgJobs\Preview\PreviewRenderer
::
class
;
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