Skip to content

Commit

Permalink
New: added author page node type
Browse files Browse the repository at this point in the history
closes #5
  • Loading branch information
Marvin Kuhn committed Sep 29, 2018
1 parent c3df7b6 commit 0640483
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 2 deletions.
37 changes: 37 additions & 0 deletions Classes/FlowQuery/Operations/FilterByAuthorOperation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace Breadlesscode\Blog\FlowQuery\Operations;

use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Eel\FlowQuery\FlowQuery;
use Neos\Eel\FlowQuery\FlowQueryException;
use Neos\Eel\FlowQuery\Operations\AbstractOperation;

class FilterByAuthorOperation extends AbstractOperation
{
/**
* {@inheritdoc}
*
* @var string
*/
static protected $shortName = 'filterByAuthor';

/**
* {@inheritdoc}
*
* @param FlowQuery $flowQuery the FlowQuery object
* @param array $arguments the arguments for this operation
* @return void
* @throws FlowQueryException
*/
public function evaluate(FlowQuery $flowQuery, array $arguments)
{
if (!is_string($arguments[0])) {
throw new FlowQueryException('The first parameter of '.self::$shortName.' should be a string');
}

$context = \array_filter($flowQuery->getContext(), function(NodeInterface $node) use ($arguments) {
return $node->getProperty('author') === $arguments[0];
});
$flowQuery->setContext($context);
}
}
56 changes: 56 additions & 0 deletions Classes/NodeCreationHandler/AuthorNodeCreationHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
namespace Breadlesscode\Blog\NodeCreationHandler;

/*
* This file is part of the Neos.Neos.Ui 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 Breadlesscode\Blog\Service\PostNodePreparationService;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Neos\Domain\Model\User;
use Neos\Neos\Ui\NodeCreationHandler\NodeCreationHandlerInterface;
use Neos\Neos\Domain\Repository\UserRepository;
use Neos\Neos\Utility\NodeUriPathSegmentGenerator;

class AuthorNodeCreationHandler implements NodeCreationHandlerInterface
{
/**
* @var UserRepository
* @Flow\Inject()
*/
protected $userRepo;

/**
* @Flow\Inject
* @var NodeUriPathSegmentGenerator
*/
protected $nodeUriPathSegmentGenerator;

/**
* Set the node title for the newly created Document node
*
* @param NodeInterface $node The newly created node
* @param array $data incoming data from the creationDialog
* @return void
* @throws \Neos\Neos\Exception
*/
public function handle(NodeInterface $node, array $data)
{
if (!$node->getNodeType()->isOfType(PostNodePreparationService::DOCUMENT_AUTHOR_TYPE)) {
return;
}
/** @var User $user */
$user = $this->userRepo->findByIdentifier($data['user']);

$node->setProperty('user', $data['user']);
$node->setProperty('title', $user->getLabel());
$node->setProperty('uriPathSegment', $this->nodeUriPathSegmentGenerator->generateUriPathSegment($node, $user->getLabel()));
}
}
5 changes: 5 additions & 0 deletions Classes/Service/PostNodePreparationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class PostNodePreparationService
*/
const DOCUMENT_POST_TYPE = 'Breadlesscode.Blog:Document.Post';

/**
* author page node type
*/
const DOCUMENT_AUTHOR_TYPE = 'Breadlesscode.Blog:Document.Author';

/**
* @Flow\Inject
* @var \Neos\Neos\Domain\Service\UserService
Expand Down
49 changes: 49 additions & 0 deletions Configuration/NodeTypes.Document.Author.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'Breadlesscode.Blog:Document.Author':
superTypes:
'Neos.Neos:Document': true

ui:
label: 'i18n'
group: 'blog'
position: 500
icon: 'far fa-user-circle'
inspector:
groups:
author:
label: 'i18n'
icon: 'far fa-user-circle'

creationDialog:
elements:
title: ~
user:
type: string
ui:
label: 'i18n'
editor: 'Neos.Neos/Inspector/Editors/SelectBoxEditor'
editorOptions:
dataSourceIdentifier: 'breadlesscode-blog-user-datasource'
minimumResultsForSearch: 3
validation:
'Neos.Flow\Validation\Validator\NumberRangeValidator': ~

options:
documentTitle: ~
nodeCreationHandlers:
user:
nodeCreationHandler: 'Breadlesscode\Blog\NodeCreationHandler\AuthorNodeCreationHandler'

properties:
user:
type: string
ui:
label: 'i18n'
inspector:
position: 10
group: author
editor: 'Neos.Neos/Inspector/Editors/SelectBoxEditor'
editorOptions:
dataSourceIdentifier: 'breadlesscode-blog-user-datasource'
minimumResultsForSearch: 3
validation:
'Neos.Flow\Validation\Validator\NumberRangeValidator': ~
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
This Neos CMS plugin is for a simple blog functionality.

## Features
- Blog categories
- Categories
- Tags
- Comments
- Author page
- Listing with pagination


Expand Down Expand Up @@ -45,17 +46,25 @@ prototype(Vendor.Xy:RecentBlogPosts) < prototype(Breadlesscode.Blog:Component.Po
Reference of some parts of the package.

### FlowQuery-Oprations

### filterByTags(*&lt;tags&gt;*)
You can filter a collection of nodes by tags. Example:
```
${ q(site).find('[instanceof Breadlesscode.Blog:Document.Post]').fliterByTags(q(node).property('tags')).get() }
```

### filterByCategories(*&lt;categories&gt;*)
You can filter a collection of nodes by tags. Example:
```
${ q(site).find('[instanceof Breadlesscode.Blog:Document.Post]').filterByCategories(q(node).property('categories')).get() }
```

### filterByAuthor(*&lt;user-identifier&gt;*)
You can filter a collection of nodes by the author. Example:
```
${ q(site).find('[instanceof Breadlesscode.Blog:Document.Post]').filterByAuthor(q(node).property('author')).get() }
```

### Eel Helper
#### Blog.getUserByIdentifier(*&lt;user-identifier&gt;*)
For quering users, e.g. the author.
Expand All @@ -75,6 +84,7 @@ All node types that this package provides.
- [Breadlesscode.Commentable:Mixin.Commentable](https://github.com/breadlesscode/neos-commentable/blob/master/Configuration/NodeTypes.Mixin.Commentable.yaml)
- [Breadlesscode.Blog:Document.CategoryBlog](Configuration/NodeTypes.Document.Category.yaml) - Category
- [Breadlesscode.Blog:Document.Tag](Configuration/NodeTypes.Document.Tag.yaml) - Tag
- [Breadlesscode.Blog:Document.Author](Configuration/NodeTypes.Document.Author.yaml) - Author

#### Content
- [Breadlesscode.Blog:Content.PostListing](Configuration/NodeTypes.Content.PostListing.yaml) - Listing of blog posts
Expand Down
18 changes: 18 additions & 0 deletions Resources/Private/Fusion/Document/Author.fusion
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
prototype(Breadlesscode.Blog:Document.Author) >
prototype(Breadlesscode.Blog:Document.Author) < prototype(Neos.Neos:Page) {
body >
body = Neos.Fusion:Tag {
attributes.class = 'blog-tag'
content = Neos.Fusion:Array {
headline = Neos.Fusion:Tag {
tagName = 'h1'
content = ${ Translation.translate('Breadlesscode.Blog:Main:author.title') + ': ' + q(documentNode).property('title')}
}
list = Breadlesscode.Blog:Component.PostList {
paginated = true
itemsPerPage = 10
collection = ${ q(site).find('[instanceof Breadlesscode.Blog:Document.Post]').filterByAuthor(q(documentNode).property('user')).get() }
}
}
}
}
8 changes: 7 additions & 1 deletion Resources/Private/Translations/de/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
<file original="" product-name="Breadlesscode.Blog" source-language="en" target-language="de" datatype="plaintext">
<body>
<trans-unit id="category.title" xml:space="preserve">
<source>Kategorie</source>
<source>Category</source>
<target xml:lang="de">Kategorie</target>
</trans-unit>
<trans-unit id="tag.title" xml:space="preserve">
<source>Tag</source>
<target xml:lang="de">Tag</target>
</trans-unit>
<trans-unit id="author.title" xml:space="preserve">
<source>Author</source>
<target xml:lang="de">Autor</target>
</trans-unit>
</body>
</file>
Expand Down
23 changes: 23 additions & 0 deletions Resources/Private/Translations/de/NodeTypes/Document/Author.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Breadlesscode.Blog" source-language="en" target-language="de" datatype="plaintext">
<body>
<trans-unit id="ui.label" xml:space="preserve">
<source>Author</source>
<target xml:lang="de">Autor</target>
</trans-unit>
<trans-unit id="groups.author" xml:space="preserve">
<source>Author</source>
<target xml:lang="de">Autor</target>
</trans-unit>
<trans-unit id="properties.user" xml:space="preserve">
<source>User</source>
<target xml:lang="de">Benutzer</target>
</trans-unit>
<trans-unit id="creationDialog.user" xml:space="preserve">
<source>User</source>
<target xml:lang="de">Benutzer</target>
</trans-unit>
</body>
</file>
</xliff>
3 changes: 3 additions & 0 deletions Resources/Private/Translations/en/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<trans-unit id="tag.title" xml:space="preserve">
<source>Tag</source>
</trans-unit>
<trans-unit id="author.title" xml:space="preserve">
<source>Author</source>
</trans-unit>
</body>
</file>
</xliff>
19 changes: 19 additions & 0 deletions Resources/Private/Translations/en/NodeTypes/Document/Author.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file original="" product-name="Breadlesscode.Blog" source-language="en" datatype="plaintext">
<body>
<trans-unit id="ui.label" xml:space="preserve">
<source>Author</source>
</trans-unit>
<trans-unit id="groups.author" xml:space="preserve">
<source>Author</source>
</trans-unit>
<trans-unit id="properties.user" xml:space="preserve">
<source>User</source>
</trans-unit>
<trans-unit id="creationDialog.user" xml:space="preserve">
<source>User</source>
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 0640483

Please sign in to comment.