Improve support for snippets throughout Winter CMS#36
Improve support for snippets throughout Winter CMS#36LukeTowers wants to merge 21 commits intomainfrom
Conversation
- Add parser method to Snippet class
Co-authored-by: Ben Thomson <git@alfreido.com>
| 'filters' => [ | ||
| 'staticPage' => ['Winter\Pages\Classes\Page', 'url'] | ||
| 'staticPage' => ['Winter\Pages\Classes\Page', 'url'], | ||
| 'parseSnippets' => ['Winter\Pages\Classes\Snippet', 'parse'], |
There was a problem hiding this comment.
We need documentation for this filter
There was a problem hiding this comment.
@LukeTowers I think we should use a modified version of the original readme.md file
ref. https://github.com/inetis-ch/oc-richeditorsnippets-plugin
Do you have a suggestion on where to integrate this content ?
|
|
||
| // Make an unique alias for this snippet based on its name and parameters | ||
| #$snippetInfo['code'] = uniqid($snippetInfo['code'] . '_' . md5(serialize($snippetInfo['properties'])) . '_'); | ||
| // the line above was commented out to allow the overriden partials in theme to be used for the component alias |
There was a problem hiding this comment.
@mjauvin could you explain this further to me?
There was a problem hiding this comment.
It's been a while and I don't recall specifically, but the snippet code value provided in the content (richeditor or elsewhere) cannot be modified, otherwise it breaks.
There was a problem hiding this comment.
Ok, I experimented a bit and the problem is if you modify the snippet code as above, the overridden markup is not found in the theme because the "alias" is totally different.
For example, let's say you have a component named "FAQ" and it's used as a snippet, if the theme creates a "partials/faq/default.htm" file to override the default component markup, obfuscating the snippet code with uniqid($snippetInfo['code'] . '_' . md5(serialize($snippetInfo['properties'])) . '_'); will prevent that overriden markup to be found (it would search "partials/{uniqueid}" which obviously won't exist.
There was a problem hiding this comment.
And I'm guessing the original reason for this code was to support multiple instances of the same component provided snippet in the same field?
There was a problem hiding this comment.
Using different snippet code would achieve the same goal.
| // the line above was commented out to allow the overriden partials in theme to be used for the component alias | ||
|
|
||
| static::attachComponentSnippetToController($snippetInfo, $controller, true); | ||
| static::cacheSnippet($snippetInfo['code'], $snippetInfo); |
There was a problem hiding this comment.
| static::cacheSnippet($snippetInfo['code'], $snippetInfo); | |
| static::cacheSnippet($snippetInfo); |
| * Store a component snippet to the cache. | ||
| * The cache is not actually saved; saveCachedSnippets() must be called to persist the cache. | ||
| */ | ||
| protected static function cacheSnippet(string $alias, array $snippetInfo): void |
There was a problem hiding this comment.
| protected static function cacheSnippet(string $alias, array $snippetInfo): void | |
| protected static function cacheSnippet(array $snippetInfo): void |
There was a problem hiding this comment.
I think there's no need to pass a seperate variable for the alias, what do you think?
| */ | ||
| protected static function cacheSnippet(string $alias, array $snippetInfo): void | ||
| { | ||
| static::$pageSnippetsCache[$alias] = $snippetInfo; |
There was a problem hiding this comment.
| static::$pageSnippetsCache[$alias] = $snippetInfo; | |
| $alias = $snippetInfo['code']; | |
| static::$pageSnippetsCache[$alias] = $snippetInfo; |
This merges the work from https://github.com/inetis-ch/oc-richeditorsnippets-plugin by @inetis-ch & @matt-pawley into the core Winter.Pages plugin.
The following features are added by this PR:
snippetsbutton in the Froala WYSIWYGricheditorfield that when clicked presents a list of registered snippets to the user and enables them to inject snippets into their richeditor content.parseSnippetsTwig filter that is used to filter content produced by saidsnippetsbutton in order to actually render the snippets.