-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Felix Gradinaru
committed
Jul 22, 2021
1 parent
38448ea
commit b102987
Showing
11 changed files
with
442 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Various temporary and editor files | ||
.fuse_hidden | ||
.sass-cache | ||
bower_components | ||
node_modules | ||
*.DS_Store | ||
/.idea | ||
.remote-sync.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
|
||
namespace CodeQ\NeosMonocleRenderer\DataSource; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\ContentRepository\Domain\Model\NodeInterface; | ||
use Neos\Neos\Service\DataSource\AbstractDataSource; | ||
use Sitegeist\Monocle\Fusion\FusionService; | ||
use Sitegeist\Monocle\Service\ConfigurationService; | ||
|
||
class NodeTypeDataSource extends AbstractDataSource | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
static protected $identifier = 'codeq-neosmonoclerenderer-nodetype'; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var FusionService | ||
*/ | ||
protected $fusionService; | ||
|
||
/** | ||
* @Flow\Inject | ||
* @var ConfigurationService | ||
*/ | ||
protected $configurationService; | ||
|
||
/** | ||
* @param NodeInterface|null $node | ||
* @param array $arguments | ||
* | ||
* @return array | ||
*/ | ||
public function getData(NodeInterface $node = null, array $arguments = []): array | ||
{ | ||
$sitePackageKey = $node->getContext()->getCurrentSite()->getSiteResourcesPackageKey(); | ||
|
||
$data = []; | ||
foreach($this->getStyleguideObjects($sitePackageKey) as $prototypeName => $styleguideObject) { | ||
$data[] = array( | ||
'label' => $styleguideObject['title'], | ||
'value' => $prototypeName, | ||
'icon' => $styleguideObject['structure']['icon'] | ||
); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @param $sitePackageKey | ||
* @param $styleguideObject | ||
* @return array | ||
* @throws \Neos\Neos\Domain\Exception | ||
*/ | ||
protected function getStyleguideObjects($sitePackageKey): array | ||
{ | ||
$fusionAst = $this->fusionService->getMergedFusionObjectTreeForSitePackage($sitePackageKey); | ||
$styleguideObjects = $this->fusionService->getStyleguideObjectsFromFusionAst($fusionAst); | ||
$prototypeStructures = $this->configurationService->getSiteConfiguration($sitePackageKey, 'ui.structure'); | ||
|
||
foreach ($styleguideObjects as $prototypeName => &$styleguideObject) { | ||
$styleguideObject['structure'] = $this->getStructureForPrototypeName($prototypeStructures, $prototypeName); | ||
} | ||
|
||
$hiddenPrototypeNamePatterns = $this->configurationService->getSiteConfiguration($sitePackageKey, 'hiddenPrototypeNamePatterns'); | ||
if (is_array($hiddenPrototypeNamePatterns)) { | ||
$alwaysShowPrototypes = $this->configurationService->getSiteConfiguration($sitePackageKey, 'alwaysShowPrototypes'); | ||
foreach ($hiddenPrototypeNamePatterns as $pattern) { | ||
$styleguideObjects = array_filter( | ||
$styleguideObjects, | ||
function ($prototypeName) use ($pattern, $alwaysShowPrototypes) { | ||
if (in_array($prototypeName, $alwaysShowPrototypes, true)) { | ||
return true; | ||
} | ||
return fnmatch($pattern, $prototypeName) === false; | ||
}, | ||
ARRAY_FILTER_USE_KEY | ||
); | ||
} | ||
} | ||
return $styleguideObjects; | ||
} | ||
|
||
/** | ||
* Find the matching structure for a prototype | ||
* | ||
* @param $prototypeStructures | ||
* @param $prototypeName | ||
* @return array | ||
*/ | ||
protected function getStructureForPrototypeName($prototypeStructures, $prototypeName) | ||
{ | ||
foreach ($prototypeStructures as $structure) { | ||
if (preg_match(sprintf('!%s!', $structure['match']), $prototypeName)) { | ||
return $structure; | ||
} | ||
} | ||
|
||
return [ | ||
'label' => 'Other', | ||
'icon' => 'icon-question', | ||
'color' => 'white' | ||
]; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
Configuration/NodeTypes.Content.PrototypeRendererNode.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'CodeQ.NeosMonocleRenderer:Content.MonocleRendererNode': | ||
label: "${String.trim(String.substr(q(node).property('prototypeName'), String.lastIndexOf(q(node).property('prototypeName'), '.') + 1))}" | ||
superTypes: | ||
'Neos.Neos:Content': true | ||
ui: | ||
label: i18n | ||
icon: 'icon-code' | ||
position: 900 | ||
inspector: | ||
groups: | ||
prototype: | ||
label: i18n | ||
icon: 'icon-cogs' | ||
position: 10 | ||
creationDialog: | ||
elements: | ||
prototypeName: | ||
type: string | ||
ui: | ||
label: i18n | ||
editor: 'Content/Inspector/Editors/SelectBoxEditor' | ||
editorOptions: | ||
dataSourceIdentifier: 'codeq-neosmonoclerenderer-nodetype' | ||
validation: | ||
'Neos.Neos/Validation/NotEmptyValidator': [] | ||
options: | ||
template: | ||
properties: | ||
prototypeName: '${data.prototypeName}' | ||
properties: | ||
prototypeName: | ||
type: string | ||
ui: | ||
label: i18n | ||
reloadIfChanged: true | ||
reloadPageIfChanged: true | ||
inspector: | ||
group: 'prototype' | ||
editor: 'Content/Inspector/Editors/SelectBoxEditor' | ||
editorOptions: | ||
dataSourceIdentifier: 'codeq-neosmonoclerenderer-nodetype' | ||
validation: | ||
'Neos.Neos/Validation/NotEmptyValidator': [] | ||
json: | ||
type: string | ||
defaultValue: '{}' | ||
ui: | ||
label: i18n | ||
reloadIfChanged: true | ||
inspector: | ||
group: 'prototype' | ||
editor: 'Neos.Neos/Inspector/Editors/CodeEditor' | ||
editorOptions: | ||
buttonLabel: i18n | ||
highlightingMode: 'text/json' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# restrict creation and editing of `CodeQ.NeosMonocleRenderer:Content.PrototypeRendererNode` nodetype to non-admins | ||
privilegeTargets: | ||
'Neos\ContentRepository\Security\Authorization\Privilege\Node\CreateNodePrivilege': | ||
'CodeQ.NeosMonocleRenderer:CreatePrototypeRendererNode': | ||
label: 'Create a new PrototypeRendererNode' | ||
matcher: 'createdNodeIsOfType("CodeQ.NeosMonocleRenderer:Content.PrototypeRendererNode")' | ||
'Neos\ContentRepository\Security\Authorization\Privilege\Node\EditNodePrivilege': | ||
'CodeQ.NeosMonocleRenderer:EditPrototypeRendererNode': | ||
label: 'Edit a PrototypeRendererNode' | ||
matcher: 'nodeIsOfType("CodeQ.NeosMonocleRenderer:Content.PrototypeRendererNode")' | ||
'Neos\ContentRepository\Security\Authorization\Privilege\Node\RemoveNodePrivilege': | ||
'CodeQ.NeosMonocleRenderer:RemovePrototypeRendererNode': | ||
label: 'Remove a PrototypeRendererNode' | ||
matcher: 'nodeIsOfType("CodeQ.NeosMonocleRenderer:Content.PrototypeRendererNode")' | ||
'Neos\ContentRepository\Security\Authorization\Privilege\Node\EditNodePropertyPrivilege': | ||
'CodeQ.NeosMonocleRenderer:EditPrototypeRendererNodeProperty': | ||
label: 'Edit a PrototypeRendererNode property' | ||
matcher: 'nodeIsOfType("CodeQ.NeosMonocleRenderer:Content.PrototypeRendererNode")' | ||
|
||
roles: | ||
## | ||
# By default this role is abstract, feel free to use it however you want. | ||
# This role is considered public API | ||
## | ||
'CodeQ.NeosMonocleRenderer:PrototypeRendererNodeEditor': | ||
abstract: true | ||
label: 'Prototype Renderer Node Editor' | ||
description: 'A user with this role is able to render any Prototype as content node.' | ||
privileges: | ||
- | ||
privilegeTarget: 'CodeQ.NeosMonocleRenderer:CreatePrototypeRendererNode' | ||
permission: GRANT | ||
- | ||
privilegeTarget: 'CodeQ.NeosMonocleRenderer:EditPrototypeRendererNode' | ||
permission: GRANT | ||
- | ||
privilegeTarget: 'CodeQ.NeosMonocleRenderer:RemovePrototypeRendererNode' | ||
permission: GRANT | ||
- | ||
privilegeTarget: 'CodeQ.NeosMonocleRenderer:EditPrototypeRendererNodeProperty' | ||
permission: GRANT | ||
|
||
'Neos.Neos:Administrator': | ||
privileges: | ||
- | ||
privilegeTarget: 'CodeQ.NeosMonocleRenderer:CreatePrototypeRendererNode' | ||
permission: GRANT | ||
- | ||
privilegeTarget: 'CodeQ.NeosMonocleRenderer:EditPrototypeRendererNode' | ||
permission: GRANT | ||
- | ||
privilegeTarget: 'CodeQ.NeosMonocleRenderer:RemovePrototypeRendererNode' | ||
permission: GRANT | ||
- | ||
privilegeTarget: 'CodeQ.NeosMonocleRenderer:EditPrototypeRendererNodeProperty' | ||
permission: GRANT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
Neos: | ||
Neos: | ||
fusion: | ||
autoInclude: | ||
CodeQ.NeosMonocleRenderer: true | ||
userInterface: | ||
translation: | ||
autoInclude: | ||
CodeQ.NeosMonocleRenderer: | ||
- 'Fusion/*' | ||
- 'NodeTypes/*' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Roland Schütz | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
53 changes: 53 additions & 0 deletions
53
Resources/Private/Fusion/Content/PrototypeRendererNode/MonocleRendererNode.fusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
prototype(CodeQ.NeosMonocleRenderer:Content.MonocleRendererNode) < prototype(Neos.Neos:ContentComponent) { | ||
@context { | ||
prototypeName = ${String.trim(q(node).property('prototypeName'))} | ||
prototypeProps = ${Json.parse(q(node).property('json') || '{}')} | ||
} | ||
|
||
renderer = Neos.Fusion:Case { | ||
noPrototypeName { | ||
condition = ${!prototypeName && node.context.inBackend} | ||
renderer = CodeQ.PrototypeRendererNode:Content.PrototypeRendererNode.ErrorMessage { | ||
name = 'noPrototypeNameNotice' | ||
} | ||
} | ||
// jsonIsInvalid { | ||
// condition = ${!prototypeProps && node.context.inBackend} | ||
// renderer = Neos.Fusion:Debug { | ||
// foo = ${prototypeProps} | ||
// } | ||
//// renderer = CodeQ.PrototypeRendererNode:Content.PrototypeRendererNode.ErrorMessage { | ||
//// name = 'jsonIsInvalidNotice' | ||
//// } | ||
// } | ||
canRender { | ||
condition = Neos.Fusion:CanRender { | ||
type = ${prototypeName} | ||
} | ||
renderer = Neos.Fusion:Renderer { | ||
type = ${prototypeName} | ||
[email protected] = ${prototypeProps} | ||
} | ||
} | ||
prototypeDoesNotExist { | ||
condition = ${node.context.inBackend} | ||
renderer = CodeQ.PrototypeRendererNode:Content.PrototypeRendererNode.ErrorMessage { | ||
name = 'prototypeDoesNotExistNotice' | ||
} | ||
} | ||
frontend { | ||
condition = true | ||
renderer = false | ||
} | ||
} | ||
} | ||
|
||
prototype(CodeQ.PrototypeRendererNode:Content.PrototypeRendererNode.ErrorMessage) < prototype(Neos.Fusion:Component) { | ||
name = '' | ||
|
||
renderer = afx` | ||
<div style="display: block; padding: 2rem; background: red; font-size: 2rem;"> | ||
{I18n.translate('CodeQ.PrototypeRendererNode:NodeTypes.Content.PrototypeRendererNode:' + props.name)} | ||
</div> | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
############################################## | ||
############################################## | ||
#### #### | ||
#### !!!DO NOT EDIT THIS FILE!!!! #### | ||
#### #### | ||
############################################## | ||
############################################## | ||
|
||
include: **/*.fusion |
44 changes: 44 additions & 0 deletions
44
Resources/Private/Translations/de/NodeTypes/Content/MonocleRendererNode.xlf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0"?> | ||
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> | ||
<file original="" source-language="en" datatype="plaintext" target-language="de"> | ||
<body> | ||
<trans-unit id="ui.label" xml:space="preserve"> | ||
<source>Monocle Renderer</source> | ||
<target xml:lang="de" state="translated">Monocle Renderer</target> | ||
</trans-unit> | ||
<trans-unit id="creationDialog.prototypeName" xml:space="preserve"> | ||
<source>Prototype Name</source> | ||
<target xml:lang="de" state="translated">Prototype Name</target> | ||
</trans-unit> | ||
<trans-unit id="properties.prototypeName" xml:space="preserve"> | ||
<source>Prototype Name</source> | ||
<target xml:lang="de" state="translated">Prototype Name</target> | ||
</trans-unit> | ||
<trans-unit id="properties.json" xml:space="preserve"> | ||
<source>Prototype Props as JSON</source> | ||
<target xml:lang="de" state="translated">Prototype Props als JSON</target> | ||
</trans-unit> | ||
<trans-unit id="properties.json.codeEditor.buttonLabel" xml:space="preserve"> | ||
<source>Edit Props</source> | ||
<target xml:lang="de" state="translated">Props bearbeiten</target> | ||
</trans-unit> | ||
<trans-unit id="groups.htmlwidget" xml:space="preserve"> | ||
<source>Settings</source> | ||
<target xml:lang="de" state="translated">Einstellungen</target> | ||
</trans-unit> | ||
|
||
<trans-unit id="noPrototypeNameNotice" xml:space="preserve"> | ||
<source>Please define a prototype name to render.</source> | ||
<target xml:lang="de" state="translated">Bitte gib einen Prototype-Namen ein.</target> | ||
</trans-unit> | ||
<trans-unit id="jsonIsInvalidNotice" xml:space="preserve"> | ||
<source>Your JSON for the Prototype props is invalid</source> | ||
<target xml:lang="de" state="translated">Das Prototype-Props JSON ist ungültig.</target> | ||
</trans-unit> | ||
<trans-unit id="prototypeDoesNotExistNotice" xml:space="preserve"> | ||
<source>The Prototype does not exist.</source> | ||
<target xml:lang="de" state="translated">Der Prototype existiert nicht.</target> | ||
</trans-unit> | ||
</body> | ||
</file> | ||
</xliff> |
Oops, something went wrong.