Commit 4cb006db authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

[TASK] Adding example class

parent 5fa656cd
<?php
namespace SGalinski\SgMail\Example;
use SGalinski\SgMail\Service\RegisterInterface;
  • We are always(!) writing the use statements below the copyright. The namespace is on top of it. PhpStorm does this automatically initially. So you placed this one manually here.

Please register or sign in to reply
/***************************************************************
* 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!
***************************************************************/
/**
* Example Registration for a Template
*
* @package SGalinski\SgMail\Example
Please register or sign in to reply
*/
class Register implements RegisterInterface {
/**
* @var array
*/
private $markers = [];
/**
* @var array
*/
private $subjects = [];
/**
* @var string
*/
private $description;
/**
* the extension key
*
* @var string
*/
private $extensionKey;
/**
* a unique name for this template
*
* @var string
*/
private $templateKey;
/**
* path where the template is located
*
* @var string
*/
private $templatePath;
/**
* initialize certain values
*
* @return mixed
Please register or sign in to reply
*/
public function init() {
$this->markers = [
[
'marker' => 'firstname',
'type' => \SGalinski\SgMail\Service\MailTemplateService::MARKER_TYPE_STRING,
'value' => 'Max',
'description' => 'The First Name of the Customer'
],
[
'marker' => 'lastname',
'type' => \SGalinski\SgMail\Service\MailTemplateService::MARKER_TYPE_STRING,
'value' => 'Mustermann',
'description' => 'The Last Name of the Customer'
]
];
$this->description = 'Description about the Template';
$this->subjects = [
'en' => 'The english subject text',
'de' => 'The german subject text'
];
$this->templateKey = 'notice_mail_admin';
$this->extensionKey = 'sg_sample';
}
/**
* call MailTemplateService registerTemplate with according values
Please register or sign in to reply
*
* @return mixed
Please register or sign in to reply
*/
public function registerTemplate() {
\SGalinski\SgMail\Service\MailTemplateService::registerTemplate(
$this->extensionKey, $this->templateKey, $this->templatePath, $this->description, $this->markers, $this->subjects
);
}
/**
* @return array
*/
public function getMarkers() {
return $this->markers;
}
/**
* @param array $markers
* @return RegisterInterface
*/
public function setMarkers($markers) {
Please register or sign in to reply
$this->markers = $markers;
return $this;
}
/**
* @return array
*/
public function getSubjects() {
return $this->subjects;
}
/**
* @param array $subjects
* @return RegisterInterface
*/
public function setSubjects($subjects) {
$this->subjects = $subjects;
return $this;
}
/**
* @return string
*/
public function getDescription() {
return $this->description;
}
/**
* @param string $description
* @return RegisterInterface
*/
public function setDescription($description) {
$this->description = $description;
return $this;
}
/**
* @return string
*/
public function getExtensionKey() {
return $this->extensionKey;
}
/**
* @param string $extensionKey
* @return RegisterInterface
*/
public function setExtensionKey($extensionKey) {
$this->extensionKey = $extensionKey;
return $this;
}
/**
* @return string
*/
public function getTemplateKey() {
return $this->templateKey;
}
/**
* @param string $templateKey
* @return RegisterInterface
*/
public function setTemplateKey($templateKey) {
$this->templateKey = $templateKey;
return $this;
}
/**
* @return string
*/
public function getTemplatePath() {
return $this->templatePath;
}
/**
* @param string $templatePath
* @return RegisterInterface
*/
public function setTemplatePath($templatePath) {
$this->templatePath = $templatePath;
return $this;
}
}
?>
\ No newline at end of file
......@@ -219,18 +219,21 @@ class MailTemplateService {
* call in extlocalconf of an extension if you have a custom register class
*
* @param RegisterInterface
* @param boolean Should the object initialize itself ?
*
* @return bool
*/
public static function registerByFile($fileNameWithNamespace) {
public static function registerByFile($fileNameWithNamespace, $initObject = TRUE) {
$registerObject = GeneralUtility::makeInstance($fileNameWithNamespace);
// check instance of interface
if (!($registerObject instanceof RegisterInterface)) {
return FALSE;
}
// object ruft registerTemplate auf, beinhaltet alles aus extlocalconf
$registerObject->init();
// object calls registerTemplate, alternative way instead of localconf call
if ($initObject) {
$registerObject->init();
}
$registerObject->registerTemplate();
return TRUE;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment