Skip to content

Commit

Permalink
[Documents] Newsletter: add option to maintain a manual edited plain-…
Browse files Browse the repository at this point in the history
…text version (#4794)
  • Loading branch information
AlexanderWeckmer authored and brusch committed Aug 2, 2019
1 parent 8e3a799 commit bb7d3f2
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 4 deletions.
Expand Up @@ -192,6 +192,12 @@ protected function setValuesToDocument(Request $request, Document $page)
$this->addSettingsToDocument($request, $page);
$this->addDataToDocument($request, $page);
$this->addPropertiesToDocument($request, $page);

// plaintext
if ($request->get('plaintext')) {
$plaintext = $this->decodeJson($request->get('plaintext'));
$page->setValues($plaintext);
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions bundles/AdminBundle/Resources/public/css/icons.css
Expand Up @@ -1821,6 +1821,10 @@
background: url(/bundles/pimcoreadmin/img/material-icons/outline-settings-24px.svg) center center no-repeat;
}

.pimcore_material_icon_text {
background: url(/bundles/pimcoreadmin/img/flat-white-icons/text.svg) center center no-repeat;
}

.pimcore_material_icon_workflow {
background: url(/bundles/pimcoreadmin/img/material-icons/outline-directions-24px.svg) center center no-repeat;
}
Expand Down
Expand Up @@ -56,6 +56,7 @@ pimcore.document.newsletter = Class.create(pimcore.document.page_snippet, {

this.sendingPanel = new pimcore.document.newsletters.sendingPanel(this);
// this.reports = new pimcore.report.panel("document_snippet", this);
this.plaintextPanel = new pimcore.document.newsletters.plaintextPanel(this);

this.tagAssignment = new pimcore.element.tag.assignment(this, "document");
this.workflows = new pimcore.element.workflows(this, "document");
Expand All @@ -67,6 +68,7 @@ pimcore.document.newsletter = Class.create(pimcore.document.page_snippet, {
var items = [];

items.push(this.edit.getLayout());
items.push(this.plaintextPanel.getLayout());
items.push(this.preview.getLayout());
if (this.isAllowed("settings")) {
items.push(this.settings.getLayout());
Expand Down Expand Up @@ -162,6 +164,14 @@ pimcore.document.newsletter = Class.create(pimcore.document.page_snippet, {
}

}

// plaintext
try {
parameters.plaintext = Ext.encode(this.plaintextPanel.getValues());
}
catch (e4) {
//console.log(e4);
}

// data
try {
Expand Down
@@ -0,0 +1,78 @@
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/

pimcore.registerNS("pimcore.document.newsletters.plaintextPanel");
pimcore.document.newsletters.plaintextPanel = Class.create({

initialize: function(document) {
this.document = document;
},

getLayout: function () {

if (this.layout == null) {

this.layout = new Ext.FormPanel({
title: t('plain_text'),
border: false,
autoScroll: true,
bodyStyle:'padding:0 10px 0 10px;',
iconCls: "pimcore_material_icon_text pimcore_material_icon",
items: [
{
xtype:'fieldset',
title: t('plain_text_email_part'),
itemId: "plaintextPanel",
collapsible: true,
autoHeight:true,
defaults: {
labelWidth: 200
},
defaultType: 'textarea',
items :[
{
fieldLabel: t('plain_text') + " (" + this.document.data.plaintext.length + ")",
maxLength: 4000,
height: 700,
width: 1400,
name: 'plaintext',
itemId: 'plaintext',
value: this.document.data.plaintext,
enableKeyEvents: true,
listeners: {
"keyup": function (el) {
el.labelEl.update(t("plain_text") + " (" + el.getValue().length + "):");
}
}
}
]
}
]
});
}

return this.layout;
},

getValues: function () {

if (!this.layout.rendered) {
throw "plaintext not available";
}

// get values
var plaintext = this.getLayout().getForm().getFieldValues();
return plaintext;
}

});
Expand Up @@ -379,6 +379,7 @@
"pimcore/document/emails/settings.js",
"pimcore/document/newsletters/settings.js",
"pimcore/document/newsletters/sendingPanel.js",
"pimcore/document/newsletters/plaintextPanel.js",
"pimcore/document/newsletters/addressSourceAdapters/default.js",
"pimcore/document/newsletters/addressSourceAdapters/csvList.js",
"pimcore/document/newsletters/addressSourceAdapters/report.js",
Expand Down
2 changes: 1 addition & 1 deletion bundles/CoreBundle/Resources/translations/de.json
Expand Up @@ -899,4 +899,4 @@
"metainfo_copy_id": "Copy ID to clipboard",
"metainfo_copy_fullpath": "Copy full path to clipboard",
"metainfo_copy_deeplink": "Copy deeplink to clipboard"
}
}
2 changes: 2 additions & 0 deletions bundles/CoreBundle/Resources/translations/en.json
Expand Up @@ -74,6 +74,8 @@
"send_newsletter": "Send Newsletter Now",
"object_filter": "Object Filter",
"add_newsletter": "Add Newsletter",
"plain_text": "Plain Text",
"plain_text_email_part": "Email Plain Text Part",
"newsletter": "Newsletter",
"crm": "CRM",
"notes_events": "Notes & Events",
Expand Down
8 changes: 6 additions & 2 deletions lib/Tool/Newsletter.php
Expand Up @@ -69,6 +69,10 @@ public static function prepareMail(
if ($sendingContainer && $sendingContainer->getParams()) {
$mail->setParams($sendingContainer->getParams());
}

if(strlen(trim($newsletterDocument->getPlaintext())) > 0) {
$mail->setBodyText(trim($newsletterDocument->getPlaintext()));
}

$contentHTML = $mail->getBodyHtmlRendered();
$contentText = $mail->getBodyTextRendered();
Expand Down Expand Up @@ -115,6 +119,8 @@ public static function prepareMail(

$mail->setBodyHtml($contentHTML);
$mail->setBodyText($contentText);
// Adds the plain text part to the message, that it becomes a multipart email
$mail->addPart($contentText, 'text/plain');
$mail->setSubject($mail->getSubjectRendered());

return $mail;
Expand All @@ -137,8 +143,6 @@ public static function sendNewsletterDocumentBasedMail(Mail $mail, SendingParamC

if (!empty($mailAddress)) {
$mail->setTo($mailAddress);
// Getting bounces
$mail->setReturnPath(key($mail->getFrom()));

$mailer = null;
// check if newsletter specific mailer is needed
Expand Down
33 changes: 32 additions & 1 deletion models/Document/Newsletter.php
Expand Up @@ -37,7 +37,14 @@ class Newsletter extends Model\Document\PageSnippet
* @var string
*/
protected $subject = '';


/**
* Contains the plain text part of the email
*
* @var string
*/
protected $plaintext = '';

/**
* Contains the from email address
*
Expand Down Expand Up @@ -109,6 +116,30 @@ public function setFrom($from)

return $this;
}

/**
* Contains the email plain text part
*
* @param string $plaintext
*
* @return $this
*/
public function setPlaintext($plaintext)
{
$this->plaintext = $plaintext;

return $this;
}

/**
* Returns the email plain text part
*
* @return string
*/
public function getPlaintext()
{
return $this->plaintext;
}

/**
* Returns the "from" email address
Expand Down

0 comments on commit bb7d3f2

Please sign in to comment.