Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_mail
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
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_mail
Commits
8657ce1d
Commit
8657ce1d
authored
6 years ago
by
Torsten Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Adding possibility to register multiple templates via single file + refactored some code
parent
d332dc00
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!10
Feature improved usability
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/Service/MailTemplateService.php
+84
-25
84 additions, 25 deletions
Classes/Service/MailTemplateService.php
with
84 additions
and
25 deletions
Classes/Service/MailTemplateService.php
+
84
−
25
View file @
8657ce1d
...
...
@@ -59,6 +59,8 @@ class MailTemplateService {
const
DEFAULT_TEMPLATE_PATH
=
'Resources/Private/Templates/SgMail/'
;
const
CACHE_NAME
=
'sg_mail_registerArrayCache'
;
const
CACHE_LIFETIME_IN_SECONDS
=
86400
;
const
REGISTER_FILE
=
'Register.php'
;
const
CONFIG_PATH
=
'Configuration/MailTemplates'
;
/**
* @var array $toAddresses
...
...
@@ -788,7 +790,7 @@ class MailTemplateService {
foreach
(
$extensionList
as
$extensionName
)
{
$extensionConfigDirectory
=
ExtensionManagementUtility
::
extPath
(
$extensionName
);
$extensionConfigDirectory
.
=
'/
Configuration/MailTemplates'
;
$extensionConfigDirectory
.
=
'/
'
.
self
::
CONFIG_PATH
;
$configFiles
=
GeneralUtility
::
getFilesInDir
(
$extensionConfigDirectory
);
foreach
(
$configFiles
as
$configFile
)
{
...
...
@@ -796,36 +798,93 @@ class MailTemplateService {
$extensionKey
=
$configArray
[
'extension_key'
];
$templateKey
=
$configArray
[
'template_key'
];
// transform template directory name: your_templates => YourTemplates/
$templateDirectoryParts
=
GeneralUtility
::
trimExplode
(
'_'
,
$configArray
[
'template_key'
]);
$templateDirectory
=
''
;
foreach
(
$templateDirectoryParts
as
$part
)
{
$templateDirectory
.
=
ucfirst
(
$part
);
if
(
$extensionKey
===
NULL
||
$templateKey
===
NULL
)
{
continue
;
}
$templateDirectory
.
=
'/'
;
$templatePath
=
ExtensionManagementUtility
::
extPath
(
$extensionName
)
.
self
::
DEFAULT_TEMPLATE_PATH
.
$templateDirectory
;
if
(
$configArray
[
'template_path'
])
{
$templatePath
=
$configArray
[
'template_key'
];
}
$registerArray
=
self
::
writeRegisterArrayEntry
(
$registerArray
,
$extensionName
,
$extensionKey
,
$templateKey
,
$configArray
);
}
}
$description
=
$configArray
[
'description'
];
$subject
=
$configArray
[
'subject'
];
$marker
=
$configArray
[
'markers'
];
$registerArray
[
$extensionKey
][
$templateKey
]
=
[
'templatePath'
=>
$templatePath
,
'description'
=>
$description
,
'marker'
=>
$marker
,
'extension'
=>
$extensionKey
,
'templateName'
=>
$templateKey
,
'subject'
=>
$subject
];
// now check for registration files with multiple templates registered
$registerArray
=
self
::
registerFromSingleFile
(
$registerArray
);
return
$registerArray
;
}
/**
* Find Register.php files in all installed extensions and register the templates
* These files can contain multiple template registrations and are structured as multi-dimensional arrays
*
* @param array $registerArray
* @return array
*/
private
static
function
registerFromSingleFile
(
array
$registerArray
)
{
$extensionList
=
ExtensionManagementUtility
::
getLoadedExtensionListArray
();
foreach
(
$extensionList
as
$extension
)
{
$extensionConfigDirectory
=
ExtensionManagementUtility
::
extPath
(
$extension
);
$extensionConfigDirectory
.
=
self
::
CONFIG_PATH
;
if
(
!
\is_dir
(
$extensionConfigDirectory
))
{
continue
;
}
$configArray
=
(
include
$extensionConfigDirectory
.
'/'
.
self
::
REGISTER_FILE
);
if
(
$configArray
)
{
foreach
(
$configArray
as
$config
)
{
$registerArray
=
self
::
writeRegisterArrayEntry
(
$registerArray
,
$config
[
'extension_key'
],
$config
[
'extension_key'
],
$config
[
'template_key'
],
$config
);
}
}
}
return
$registerArray
;
}
/**
* writes a single entry into the register array
*
* @param array $registerArray
* @param string $extensionName
* @param string $extensionKey
* @param string $templateKey
* @param array $configArray
* @return array
*/
private
static
function
writeRegisterArrayEntry
(
array
$registerArray
,
$extensionName
,
$extensionKey
,
$templateKey
,
array
$configArray
)
{
// transform template directory name: your_templates => YourTemplates/
$templateDirectoryParts
=
GeneralUtility
::
trimExplode
(
'_'
,
$configArray
[
'template_key'
]);
$templateDirectory
=
''
;
foreach
(
$templateDirectoryParts
as
$part
)
{
$templateDirectory
.
=
ucfirst
(
$part
);
}
$templateDirectory
.
=
'/'
;
$templatePath
=
ExtensionManagementUtility
::
extPath
(
$extensionName
)
.
self
::
DEFAULT_TEMPLATE_PATH
.
$templateDirectory
;
if
(
$configArray
[
'template_path'
])
{
$templatePath
=
$configArray
[
'template_key'
];
}
$description
=
$configArray
[
'description'
];
$subject
=
$configArray
[
'subject'
];
$marker
=
$configArray
[
'markers'
];
$registerArray
[
$extensionKey
][
$templateKey
]
=
[
'templatePath'
=>
$templatePath
,
'description'
=>
$description
,
'marker'
=>
$marker
,
'extension'
=>
$extensionKey
,
'templateName'
=>
$templateKey
,
'subject'
=>
$subject
];
return
$registerArray
;
}
...
...
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