Skip to content
Snippets Groups Projects

dev#160166 : CkEditor placeholders plugin

Merged Alex Arnaud requested to merge dev#160166_newsletters_placeholders into master
All threads resolved!
Compare and Show latest version
9 files
+ 55
98
Preferences
Compare changes
Files
9
@@ -159,11 +159,14 @@ class Class_Newsletter_TemplateHelper {
$entities = $this->_renderContent($mail_renderer_function);
$unsubscribe = call_user_func([$this, $unsubscribe_function]);
if ($this->_hasRecordsPlaceholder($raw))
$this->_replaceRecordsPlaceHolder($raw, $entities, $implode_callback);
foreach (['records', 'articles'] as $element_type)
if ($this->_hasPlaceholder($raw, $element_type)){
$raw = str_replace("[newsletter_$element_type]",
$this->_implode($implode_callback, $entities[$element_type] ?? []),
$raw);
unset($entities[$element_type]);
}
if ($this->_hasArticlesPlaceholder($raw))
$this->_replaceArticlesPlaceHolder($raw, $entities, $implode_callback);
$content = [$raw,
$this->_implode($implode_callback,
@@ -172,7 +175,7 @@ class Class_Newsletter_TemplateHelper {
$unsubscribe];
return $this->_implode($implode_callback, array_filter($content));
}
}
protected function _implode(string $implode_callback, array $content) : string {
@@ -182,43 +185,8 @@ class Class_Newsletter_TemplateHelper {
}
protected function _hasRecordsPlaceholder(string $content) : bool {
return str_contains($content, '[newsletter_records]');
}
protected function _replaceRecordsPlaceHolder(string &$content,
array &$entities,
string $implode_callback) : self {
$content = str_replace('[newsletter_records]',
$this->_implode($implode_callback,$entities['records'] ?? []),
$content);
unset($entities['records']);
return $this;
}
protected function _hasArticlesPlaceholder(string $content) : bool {
return str_contains($content, '[newsletter_articles]');
}
protected function _replaceArticlesPlaceHolder(string &$content,
array &$entities,
string $implode_callback) : self {
$content = str_replace('[newsletter_articles]',
$this->_implode($implode_callback, $entities['articles'] ?? []),
$content);
unset($entities['articles']);
return $this;
protected function _hasPlaceholder(string $content, string $element_type) : bool {
return str_contains($content, "[newsletter_$element_type]");
}