Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Update code to reflect changes in template layer #556

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Actions/NotifyUsersWorkflowAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Symbiote\AdvancedWorkflow\Actions;

use SilverStripe\Control\Email\Email;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\TextareaField;
Expand All @@ -14,7 +15,8 @@
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
use SilverStripe\Model\ArrayData;
use SilverStripe\View\SSViewer;
use SilverStripe\View\TemplateEngine;
use SilverStripe\View\ViewLayerData;
use Swift_RfcComplianceException;
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowAction;
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowInstance;
Expand Down Expand Up @@ -134,10 +136,7 @@ public function execute(WorkflowInstance $workflow)
]);
}


$view = SSViewer::fromString($this->EmailTemplate);
$this->extend('updateView', $view);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what anyone would have used that extension point for, but it wouldn't be useful now we're not using SSViewer at all anyway.


$engine = Injector::inst()->create(TemplateEngine::class);
foreach ($members as $member) {
if ($member->Email) {
// We bind in the assignee at this point, as it changes each loop iteration
Expand All @@ -146,7 +145,7 @@ public function execute(WorkflowInstance $workflow)
$item->Assignee = ArrayData::create($assigneeVars);
}

$body = $view->process($item);
$body = $engine->renderString($this->EmailTemplate, ViewLayerData::create($item));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EmailTemplate value isn't hardcoded, so could be updated at a project level to be whatever template syntax the devs want to use, therefore use TemplateEngine not explicitly SSTemplateEngine


$email = Email::create();
try {
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/WorkflowDefinitionImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function parseYAMLImport($source)
$convertLF = str_replace(array("\r\n", "\r"), "\n", $source ?? '');
/*
* Remove illegal colons from Transition/Action titles, otherwise sfYamlParser will barf on them
* Note: The regex relies on there being single quotes wrapped around these in the export .ss template
* Note: The regex relies on there being single quotes wrapped around these in the export template
*/
$converted = preg_replace("#('[^:\n][^']+)(:)([^']+')#", "$1;$3", $convertLF ?? '');
$parts = preg_split('#^---$#m', $converted ?? '', -1, PREG_SPLIT_NO_EMPTY);
Expand Down
Loading