Skip to content

Commit b8e47fc

Browse files
authored
Merge pull request #4 from jonnitto/master
Improve fusion rendering
2 parents 7b8d410 + 5f450ba commit b8e47fc

18 files changed

+312
-384
lines changed

Classes/Service/EmbedService.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,10 @@ public function initializeObject()
8686
* @throws NodeException
8787
* @throws NodeTypeNotFoundException
8888
*/
89-
public function nodeUpdated(NodeInterface $node, Workspace $targetWorkspace = null): void
89+
public function nodeUpdated(NodeInterface $node): void
9090
{
9191

92-
$nodeType = $node->getNodeType()->getName();
93-
94-
if ($nodeType === 'BetterEmbed.NeosEmbed:Item') {
92+
if ($node->getNodeType()->isOfType('BetterEmbed.NeosEmbed:Mixin.Item')) {
9593
$url = $node->getProperty('url');
9694

9795
if (!empty($url)) {
@@ -109,12 +107,10 @@ public function nodeUpdated(NodeInterface $node, Workspace $targetWorkspace = nu
109107
* @throws NodeException
110108
* @throws NodeTypeNotFoundException
111109
*/
112-
public function nodeRemoved(NodeInterface $node, Workspace $targetWorkspace = null): void
110+
public function nodeRemoved(NodeInterface $node): void
113111
{
114112

115-
$nodeType = $node->getNodeType()->getName();
116-
117-
if ($nodeType === 'BetterEmbed.NeosEmbed:Item') {
113+
if ($node->getNodeType()->isOfType('BetterEmbed.NeosEmbed:Mixin.Item')) {
118114
$url = $node->getProperty('url');
119115

120116
if (!empty($url)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'BetterEmbed.NeosEmbed:Content.Item':
2+
superTypes:
3+
'Neos.Neos:Content': true
4+
'BetterEmbed.NeosEmbed:Mixin.Item': true
5+
ui:
6+
label: Better Embed
7+
icon: plus

Configuration/NodeTypes.BetterEmbed.Record.yaml

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
BetterEmbed.NeosEmbed:Record:
2-
abstract: false
1+
'BetterEmbed.NeosEmbed:Record':
32
superTypes:
43
'Neos.Neos:Document': true
5-
ui:
6-
inlineEditable: true
7-
inspector:
8-
groups:
9-
settings:
10-
label: Settings
11-
position: 4
12-
icon: 'icon-gear'
134
properties:
145
url:
156
type: string

Configuration/NodeTypes.Mixin.Content.yaml

-4
This file was deleted.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
BetterEmbed.NeosEmbed:Mixin.Include:
1+
'BetterEmbed.NeosEmbed:Mixin.Include':
22
abstract: true
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
BetterEmbed.NeosEmbed:Item:
2-
abstract: false
1+
'BetterEmbed.NeosEmbed:Mixin.Item':
2+
abstract: true
33
superTypes:
4-
'BetterEmbed.NeosEmbed:Mixin.Content': true
4+
'BetterEmbed.NeosEmbed:Mixin.Include': true
55
ui:
6-
label: Better Embed
7-
icon: plus
8-
group: general
96
inlineEditable: true
107
inspector:
118
groups:
129
settings:
1310
label: Settings
14-
position: 4
15-
icon: 'icon-gear'
11+
icon: gear
1612
properties:
1713
url:
1814
type: string
1915
ui:
2016
label: 'URL to embed'
2117
reloadPageIfChanged: true
2218
inspector:
23-
group: 'settings'
19+
group: settings
2420
record:
2521
type: reference
2622
ui:
2723
label: 'Better Embed Record'
2824
reloadPageIfChanged: true
2925
inspector:
30-
#group: 'settings'
3126
editorOptions:
3227
startingPoint: '/embeds'
33-
nodeTypes: ['BetterEmbed.NeosEmbed:Record']
34-
28+
nodeTypes: ['BetterEmbed.NeosEmbed:Document.Record']

Configuration/Settings.yaml Configuration/Settings.BetterEmbed.yaml

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
Neos:
2-
Neos:
3-
fusion:
4-
autoInclude:
5-
BetterEmbed.NeosEmbed: true
6-
71
BetterEmbed:
82
NeosEmbed:
93
text:

Configuration/Settings.Neos.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Neos:
2+
Neos:
3+
fusion:
4+
autoInclude:
5+
BetterEmbed.NeosEmbed: true

Resources/Private/Fusion/Component/Default.fusion Resources/Private/Fusion/Component/Default/Default.fusion

+7-49
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ prototype(BetterEmbed.NeosEmbed:Component.Default) < prototype(Neos.Fusion:Compo
1717
labelCancel = ${Configuration.setting('BetterEmbed.NeosEmbed.text.labelCancel')}
1818

1919
renderer = afx`
20-
<BetterEmbed.NeosEmbed:Component.Default.Tag itemType={props.itemType} attributes.data-embed-html={Json.stringify(props.embedHtml)}>
20+
<BetterEmbed.NeosEmbed:Component.Default.Fragment.Tag itemType={props.itemType} data-embed-html={Json.stringify(props.embedHtml)}>
2121
<button type="button" class="betterembed__show-original-element js-betterembed-show-message"></button>
2222
<div class="betterembed__item">
2323
<header>
@@ -31,67 +31,25 @@ prototype(BetterEmbed.NeosEmbed:Component.Default) < prototype(Neos.Fusion:Compo
3131
<p @if.isset={props.msgGdpr}>
3232
<strong>{props.msgGdpr}</strong>
3333
</p>
34-
<a href="javascript:;" class="betterembed__msg-button-primary js-betterembed-load-remote">{props.labelOk}</a>
35-
<a href="javascript:;" class="betterembed__msg-button-secondary js-betterembed-close">{props.labelCancel}</a>
34+
<button type="button" class="betterembed__msg-button-primary js-betterembed-load-remote">{props.labelOk}</button>
35+
<button type="button" class="betterembed__msg-button-secondary js-betterembed-close">{props.labelCancel}</button>
3636
</div>
3737
<div @if.render={props.thumbnailUrl} class="betterembed__media">
38-
<Neos.Neos:ImageTag asset={props.thumbnail} alt="embed image"/>
38+
<Neos.Neos:ImageTag asset={props.thumbnail} alt="embed image"/>
3939
</div>
4040
<h3 @if.render={props.title} class="betterembed__title">{props.title}</h3>
4141
<div class="betterembed__text">
42-
{props.body} <a href={props.url} target="_blank" class="betterembed__read-more">read more</a>
42+
{props.body} <a href={props.url} class="betterembed__read-more">read more</a>
4343
</div>
4444
<footer class="betterembed__footer">
4545
<span @if.render={props.authorName} class="betterembed__author">
46-
<a href={props.authorUrl} target="_blank">{props.authorName}</a>
46+
<a href={props.authorUrl}>{props.authorName}</a>
4747
</span>
4848
<span @if.render={props.datePublished}> {Date.format(props.datePublished, 'd.m.Y')}</span>
4949
</footer>
5050
</div>
5151
</div>
5252
<div class="betterembed__embed"></div>
53-
</BetterEmbed.NeosEmbed:Component.Default.Tag>
53+
</BetterEmbed.NeosEmbed:Component.Default.Fragment.Tag>
5454
`
5555
}
56-
57-
prototype(BetterEmbed.NeosEmbed:Component.Default.Schema) < prototype(Neos.Fusion:Tag) {
58-
tagName = ''
59-
}
60-
61-
prototype(BetterEmbed.NeosEmbed:Component.Default.Tag) < prototype(Neos.Fusion:Tag) {
62-
@context.itemType = ${this.itemType}
63-
@context.defaultClass = 'betterembed js-betterembed'
64-
65-
tagName = 'article'
66-
67-
attributes.class = Neos.Fusion:Case {
68-
twitter {
69-
condition = ${itemType == 'Twitter'}
70-
renderer = ${defaultClass + ' betterembed--twitter'}
71-
}
72-
73-
youtube {
74-
condition = ${itemType == 'YouTube'}
75-
renderer = ${defaultClass + ' betterembed--youtube'}
76-
}
77-
78-
facebook {
79-
condition = ${itemType == 'Facebook'}
80-
renderer = ${defaultClass + ' betterembed--facebook'}
81-
}
82-
83-
github {
84-
condition = ${itemType == 'GitHub'}
85-
renderer = ${defaultClass + ' betterembed--github'}
86-
}
87-
88-
default {
89-
condition = true
90-
renderer = ${defaultClass}
91-
92-
}
93-
}
94-
}
95-
96-
97-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
prototype(BetterEmbed.NeosEmbed:Component.Default.Fragment.Tag) < prototype(Neos.Fusion:Component) {
2+
tagName = 'article'
3+
itemType = null
4+
content = null
5+
6+
@if.shouldRender = ${this.tagName && this.itemType && this.content}
7+
8+
renderer = Neos.Fusion:Tag {
9+
tagName = ${props.tagName}
10+
attributes {
11+
class = ${['js-betterembed', 'betterembed', props.itemType ? String.toLowerCase('betterembed--' + props.itemType) : null]}
12+
@ignoreProperties = ${['tagName','itemType','content']}
13+
@apply.spread = ${props}
14+
}
15+
content = ${props.content}
16+
content.@process.convertToFinalUri = Neos.Neos:ConvertUris
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
prototype(BetterEmbed.NeosEmbed:Component.Item) < prototype(Neos.Fusion:Component) {
2+
recordNode = ${q(node).property('record')}
3+
4+
identifier = ${'embed-form-' + q(node).property('_identifier')}
5+
titel = ${q(this.recordNode).property('title')}
6+
url = ${q(this.recordNode).property('url')}
7+
thumbnail = ${q(this.recordNode).property('thumbnail')}
8+
thumbnailUrl = ${q(this.recordNode).property('thumbnailUrl')}
9+
thumbnailContentType = ${q(this.recordNode).property('thumbnailContentType')}
10+
thumbnailContent = ${q(this.recordNode).property('thumbnailContent')}
11+
embedHtml = ${q(this.recordNode).property('embedHtml')}
12+
body = ${q(this.recordNode).property('body')}
13+
datePublished = ${q(this.recordNode).property('publishedAt')}
14+
authorName = ${q(this.recordNode).property('authorName')}
15+
authorImage = ${q(this.recordNode).property('authorImage')}
16+
authorUrl = ${q(this.recordNode).property('authorUrl')}
17+
itemType = ${q(this.recordNode).property('itemType')}
18+
19+
@if.hasRecordOrInBackend = ${this.recordNode || node.context.inBackend}
20+
21+
renderer = afx`
22+
<BetterEmbed.NeosEmbed:Component.Renderer @if.set={props.recordNode} @key='renderer' />
23+
<div class='better-embed-placeholder' @if.notSet={!props.recordNode} @key='placeholder'>
24+
<div class='heading'>Please set a url in the inspector panel</div>
25+
</div>
26+
`
27+
28+
@cache {
29+
mode = 'cached'
30+
entryIdentifier {
31+
node = ${node}
32+
}
33+
entryTags {
34+
1 = ${Neos.Caching.nodeTag(node)}
35+
2 = ${Neos.Caching.nodeTypeTag('BetterEmbed.NeosEmbed:Document.Record', node)}
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
prototype(BetterEmbed.NeosEmbed:Component.Renderer) < prototype(Neos.Fusion:Case) {
2+
default {
3+
condition = true
4+
renderer = afx`<BetterEmbed.NeosEmbed:Component.Default {...props} />`
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
prototype(BetterEmbed.NeosEmbed:Content.Item) < prototype(Neos.Neos:ContentComponent) {
2+
3+
renderer = afx`
4+
<BetterEmbed.NeosEmbed:Component.Item {...props} />
5+
`
6+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
prototype(Neos.Neos:Page) {
2+
head.betterEmbedCss = Neos.Fusion:Component {
3+
@position = 'end'
4+
includeAssets = ${q(documentNode).children('[instanceof Neos.Neos:ContentCollection]').find('[instanceof BetterEmbed.NeosEmbed:Mixin.Include]').is() || q(documentNode).is('[instanceof BetterEmbed.NeosEmbed:Mixin.Include]')}
5+
6+
renderer = afx`
7+
<link rel='stylesheet' @if.set={props.includeAssets} @key='styles'>
8+
<Neos.Fusion:ResourceUri @path='attributes.href' path='resource://BetterEmbed.NeosEmbed/Public/css/embed.css' />
9+
</link>
10+
<link rel='stylesheet' @if.inBackend={node.context.inBackend} @key='backend'>
11+
<Neos.Fusion:ResourceUri @path='attributes.href' path='resource://BetterEmbed.NeosEmbed/Public/css/backend.css' />
12+
</link>
13+
<script type='text/javascript' defer @if.set={props.includeAssets} @key='javscript'>
14+
<Neos.Fusion:ResourceUri @path='attributes.src' path='resource://BetterEmbed.NeosEmbed/Public/js/embed.js' />
15+
</script>
16+
`
17+
}
18+
}

0 commit comments

Comments
 (0)