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

WIP Re-add Neos7 Flicker plugin for testing the fusion plugin #190

Draft
wants to merge 2 commits into
base: 9.0
Choose a base branch
from
Draft
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
81 changes: 81 additions & 0 deletions Classes/Controller/FlickrController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
namespace Neos\Demo\Controller;

/*
* This file is part of the Neos.Demo package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;

/**
* Controller that displays flickr photo streams
*/
class FlickrController extends ActionController
{
/**
* @Flow\InjectConfiguration(path="flickr.tagStreamUriPattern")
* @var string
*/
protected $tagStreamUriPattern;

/**
* @Flow\InjectConfiguration(path="flickr.userStreamUriPattern")
* @var string
*/
protected $userStreamUriPattern;

/**
* @return void|string
*/
public function tagStreamAction()
{
$tags = $this->request->getInternalArgument('__tags');
if ($tags === null || $tags === '') {
return '<p>Please specify Flickr tag(s)</p>';
}
$endpointUrl = sprintf($this->tagStreamUriPattern, $tags);

$this->view->assign('tags', $tags);
$this->view->assign('feed', $this->fetchStream($endpointUrl));
}

/**
* @param string|null $userId
* @return void|string
*/
public function userStreamAction($userId = null)
{
if ($userId === null) {
return '<p>No user specified</p>';
}
$endpointUrl = sprintf($this->userStreamUriPattern, $userId);
$this->view->assign('feed', $this->fetchStream($endpointUrl));
}

/**
* @param string $endpointUrl
* @return array
*/
protected function fetchStream(string $endpointUrl)
{
$stream = file_get_contents($endpointUrl);
return json_decode($stream, true);
}

/**
* Disable the default error flash message
*
* @return boolean
*/
protected function getErrorFlashMessage()
{
return false;
}
}
7 changes: 3 additions & 4 deletions Configuration/Policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

privilegeTargets:
'Neos\Flow\Security\Authorization\Privilege\Method\MethodPrivilege':

Neos_Demo_RegistrationAccess:
matcher: method(Neos\Demo\Controller\RegistrationController->(index|newAccount|createAccount|createTemporaryAccount)Action())
Neos_Demo_FlickrAccess:
matcher: method(Neos\Demo\Controller\FlickrController->(tagStream|userStream)Action())

roles:
'Neos.Flow:Everybody':
privileges:
- privilegeTarget: Neos_Demo_RegistrationAccess
- privilegeTarget: Neos_Demo_FlickrAccess
permission: GRANT
6 changes: 6 additions & 0 deletions Configuration/Settings.Flickr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

Neos:
Demo:
flickr:
tagStreamUriPattern: 'http://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&tags=%s'
userStreamUriPattern: 'http://api.flickr.com/services/feeds/photos_public.gne?format=json&nojsoncallback=1&id=%s'
33 changes: 33 additions & 0 deletions NodeTypes/Content/Flickr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
##
# A simple "Flickr" plugin that demonstrates the "PluginViews"-feature
#
'Neos.Demo:Content.Flickr':
superTypes:
'Neos.Demo:Constraint.Content.Main': true
'Neos.Neos:Plugin': true
ui:
label: 'Flickr Plugin'
icon: 'icon-flickr'
inspector:
groups:
'feed':
label: 'Feed'
icon: 'icon-rss'
help:
message: 'Displays a gallery of images from a flickr stream based on tags.'
options:
# todo weren't plugin views removed? https://github.com/neos/neos-development-collection/pull/4330
'pluginViews':
'UserFeed':
label: 'Neos.Demo:NodeTypes.Content.Flickr:options.pluginViews.userFeed'
controllerActions:
'Neos\Demo\Controller\FlickrController': ['userStream']
Comment on lines +18 to +24
Copy link
Member Author

Choose a reason for hiding this comment

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

is this dead code?

Copy link
Member

@kitsunet kitsunet Feb 21, 2024

Choose a reason for hiding this comment

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

pluginViews? Yeah we removed those. Which technically means we broke this plugin, because people said no one ever uses plugin views 🙈

properties:
'tags':
type: string
defaultValue: ''
ui:
label: "Tags"
reloadIfChanged: true
inspector:
group: 'feed'
10 changes: 10 additions & 0 deletions Resources/Private/Fusion/Content/Flickr.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
##
# "Flickr" element, extending "Plugin"
#
prototype(Neos.Demo:Content.Flickr) < prototype(Neos.Neos:Plugin) {
package = 'Neos.Demo'
controller = 'Flickr'
action = 'tagStream'

tags = ${q(node).property('tags')}
}
3 changes: 3 additions & 0 deletions Resources/Private/Partials/Flickr/Photo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="{photo.link}" target="_blank" title="{photo.title} - published on {photo.published -> f:format.date(format: 'Y-m-d')}">
<img src="{photo.media.m}" alt="{photo.title}" class="img-responsive img-thumbnail" />
</a>
13 changes: 13 additions & 0 deletions Resources/Private/Templates/Flickr/TagStream.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="flickr-stream">
<h3>Photo Stream for tag(s) "{tags}"</h3>
<ul class="clearfix">
<f:for each="{feed.items}" as="photo">
<li class="pull-left">
<f:render partial="Flickr/Photo" arguments="{photo: photo}" />
<p>
<f:link.action action="userStream" arguments="{userId: photo.author_id}">Show more photos by "{photo.author}"</f:link.action>
Copy link
Member Author

Choose a reason for hiding this comment

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

that link cannot be resolved:

Could not resolve a route and its corresponding URI for the given parameters. This may be due to referring to a not existing package / controller / action while building a link or URI. Refer to log and check the backtrace for more details

arguments:

{
  "node": "live__eyJsYW5ndWFnZSI6ImVuX1VTIn0=__336d96a5-b6c6-7d81-685f-89d32c37756e",
  "@package": "Neos.Neos",
  "@controller": "Frontend\\Node",
  "@action": "show",
  "@format": "html",
  "--neos_demo-content_flickr": {
    "@package": "neos.demo",
    "@controller": "flickr",
    "@action": "userstream",
    "@format": "html",
    "userId": "187194180@N06"
  }
}

Copy link
Member

@kitsunet kitsunet Feb 21, 2024

Choose a reason for hiding this comment

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

Is "node" in this a correct representation for a frontend node in a route?
The rest seems fine to me...

Copy link
Member Author

Choose a reason for hiding this comment

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

ah checked out the actual 7.3 demo and it seems the way this plugin was engineered it somehow realied on plugin views .. thats probably why it wont work?

The "master" page
image

structure
image

"plugin" page

image

Copy link
Member

Choose a reason for hiding this comment

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

could be, but in theory it should just be able to link to the page and switch to this action then. like views were never needed for multiple actions, just if you wanted to split those actions to different pages.

Copy link
Member Author

Choose a reason for hiding this comment

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

i dont understand ... not even linking to the same page works:

public function tagStreamAction()
{
    return $this->uriBuilder->uriFor('tagStream');

Copy link
Member Author

Choose a reason for hiding this comment

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

oh wait a second ... i think i answered

Is "node" in this a correct representation for a frontend node in a route?

to quickly in my head node is usually a node address object i think. And yess 💯 now the links resolve :D

Copy link
Member Author

@mhsdesign mhsdesign Feb 22, 2024

Choose a reason for hiding this comment

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

</p>
</li>
</f:for>
</ul>
</div>
13 changes: 13 additions & 0 deletions Resources/Private/Templates/Flickr/UserStream.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="flickr-stream">
<h3>{feed.title}</h3>
<ul class="clearfix">
<f:for each="{feed.items}" as="photo">
<li class="pull-left">
<f:render partial="Flickr/Photo" arguments="{photo: photo}" />
<p>
<f:link.action action="tagStream">Back to tag stream</f:link.action>
</p>
</li>
</f:for>
</ul>
</div>