diff --git a/extensions/Article/Command/DisplayCommandHandler.php b/extensions/Article/Command/DisplayCommandHandler.php
index c157d1978f..37381f54f4 100644
--- a/extensions/Article/Command/DisplayCommandHandler.php
+++ b/extensions/Article/Command/DisplayCommandHandler.php
@@ -8,7 +8,6 @@
namespace Joomla\Extension\Article\Command;
-use Joomla\Content\Type\Attribution;
use Joomla\Content\Type\Compound;
use Joomla\Content\Type\Headline;
use Joomla\Content\Type\Paragraph;
@@ -34,7 +33,6 @@ protected function getElements(EntityInterface $entity)
'section',
[
new Headline($child->title, 2),
- $child->author != $article->author ? new Attribution('Contribution from', $child->author) : null,
new Paragraph($child->body),
]
);
diff --git a/extensions/Article/Entity/Article.xml b/extensions/Article/Entity/Article.xml
index 2593936a2e..fa7840b1e2 100644
--- a/extensions/Article/Entity/Article.xml
+++ b/extensions/Article/Entity/Article.xml
@@ -37,13 +37,6 @@
description="COM_CONTENT_FIELD_ARTICLETEXT_DESC"
/>
-
-
entity->category))
+ {
+ return $query->elements;
+ }
+
$category = $query->entity->category;
$elements = $query->elements;
diff --git a/extensions/Category/Listener/AddRelationListener.php b/extensions/Category/Listener/AddRelationListener.php
index f81184bc83..ce1b1e7935 100644
--- a/extensions/Category/Listener/AddRelationListener.php
+++ b/extensions/Category/Listener/AddRelationListener.php
@@ -18,7 +18,7 @@
/**
* Class AddRelationListener
*
- * @package Joomla\Extension\Content
+ * @package Joomla\Extension\Category
*
* @since 1.0
*/
@@ -33,10 +33,16 @@ class AddRelationListener
*/
public function addCategoryRelation(AfterCreateDefinitionEvent $event)
{
+ // @todo belongs to the relation table as well
+ if ($event->getArgument('entityName') != 'Article')
+ {
+ return ;
+ }
+
/** @var \Joomla\ORM\Entity\EntityBuilder $builder */
$builder = $event->getArgument('builder');
- // @todo the relation needs to be looked up here trough a relation table */
+ // @todo the relation needs to be looked up here trough a relation table
$id = 1;
$relation = new HasOne(['id' => 1, 'name' => 'category_id', 'type' => 'hasOne', 'entity' => 'Category', 'reference' => 'id']);
diff --git a/extensions/User/Command/AddAuthorContentTypesHandler.php b/extensions/User/Command/AddAuthorContentTypesHandler.php
new file mode 100644
index 0000000000..222bdac328
--- /dev/null
+++ b/extensions/User/Command/AddAuthorContentTypesHandler.php
@@ -0,0 +1,38 @@
+entity->author))
+ {
+ return $query->elements;
+ }
+
+ $author = $query->entity->author;
+
+ $elements = $query->elements;
+ $elements['author'] = new Attribution('Contribution from ', $author->name);
+ return $elements;
+ }
+}
diff --git a/extensions/User/Command/AddLoggedInUserContentTypesHandler.php b/extensions/User/Command/AddLoggedInUserContentTypesHandler.php
new file mode 100644
index 0000000000..40068c80b7
--- /dev/null
+++ b/extensions/User/Command/AddLoggedInUserContentTypesHandler.php
@@ -0,0 +1,36 @@
+getSession()->get('User');
+
+ $elements = [
+ 'user' => new Attribution('Logged in user ', $user ? $user->name : 'Anonymous')
+ ];
+ $elements += $query->elements;
+ return $elements;
+ }
+}
diff --git a/extensions/User/Command/DisplayCommand.php b/extensions/User/Command/DisplayCommand.php
new file mode 100644
index 0000000000..38dfdfcc0e
--- /dev/null
+++ b/extensions/User/Command/DisplayCommand.php
@@ -0,0 +1,22 @@
+name, 1);
+ $elements['body'] = new Paragraph('Username: ' . $entity->username);
+
+ return $elements;
+ }
+}
diff --git a/extensions/User/Entity/User.xml b/extensions/User/Entity/User.xml
new file mode 100644
index 0000000000..b226d85faf
--- /dev/null
+++ b/extensions/User/Entity/User.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/extensions/User/Listener/AddRelationListener.php b/extensions/User/Listener/AddRelationListener.php
new file mode 100644
index 0000000000..25cfe40b76
--- /dev/null
+++ b/extensions/User/Listener/AddRelationListener.php
@@ -0,0 +1,52 @@
+getArgument('entityName') != 'Article')
+ {
+ return ;
+ }
+
+ /** @var \Joomla\ORM\Entity\EntityBuilder $builder */
+ $builder = $event->getArgument('builder');
+
+ // @todo the relation needs to be looked up here trough a relation table
+ $id = 1;
+
+ $relation = new HasOne(['id' => 1, 'name' => 'author_id', 'type' => 'hasOne', 'entity' => 'User', 'reference' => 'id']);
+
+ $builder->handleHasOne($relation, new Locator([new RecursiveDirectoryStrategy(__DIR__ . '/../Entity')]));
+ }
+}
diff --git a/extensions/User/config/extension.yml b/extensions/User/config/extension.yml
new file mode 100644
index 0000000000..5076af6860
--- /dev/null
+++ b/extensions/User/config/extension.yml
@@ -0,0 +1,12 @@
+listeners:
+ AddRelationListener:
+ class: \Joomla\Extension\User\Listener\AddRelationListener
+ events:
+ onAfterCreateDefinition: addAuthorRelation
+queryhandlers:
+ AddAuthorContentTypesHandler:
+ class: \Joomla\Extension\User\Command\AddAuthorContentTypesHandler
+ query: \Joomla\Cms\Service\ContentTypeQuery
+ AddLoggedInUserContentTypesHandler:
+ class: \Joomla\Extension\User\Command\AddLoggedInUserContentTypesHandler
+ query: \Joomla\Cms\Service\ContentTypeQuery
diff --git a/installation/demo.php b/installation/demo.php
index efe3004ad0..1cea42d038 100644
--- a/installation/demo.php
+++ b/installation/demo.php
@@ -45,6 +45,12 @@
'body' => 'Demo category body',
'parent_id' => 0
]
+ ],
+ 'User' => [
+ [
+ 'username' => 'demo',
+ 'name' => 'Demo User'
+ ]
]
];
diff --git a/libraries/incubator/Cms/Service/BasicDisplayCommandHandler.php b/libraries/incubator/Cms/Service/BasicDisplayCommandHandler.php
index 94640aa3c6..34b010ea8c 100644
--- a/libraries/incubator/Cms/Service/BasicDisplayCommandHandler.php
+++ b/libraries/incubator/Cms/Service/BasicDisplayCommandHandler.php
@@ -8,7 +8,6 @@
namespace Joomla\Cms\Service;
-use Joomla\Content\Type\Attribution;
use Joomla\Content\Type\Compound;
use Joomla\Content\Type\Headline;
use Joomla\Content\Type\Paragraph;
@@ -65,10 +64,6 @@ protected function getElements(EntityInterface $entity)
{
$elements['title'] = new Headline($entity->title, 1);
}
- if ($entity->has('author'))
- {
- $elements['author'] = new Attribution('Written by', $entity->author);
- }
if ($entity->has('teaser'))
{
$elements['teaser'] = new Paragraph($entity->teaser, Paragraph::EMPHASISED);
diff --git a/libraries/incubator/Content/Type/Attribution.php b/libraries/incubator/Content/Type/Attribution.php
index 3cf5bb930f..cce68f84e2 100644
--- a/libraries/incubator/Content/Type/Attribution.php
+++ b/libraries/incubator/Content/Type/Attribution.php
@@ -24,8 +24,8 @@ class Attribution extends AbstractContentType
/**
* Attribution constructor.
*
- * @param string $label The text before the author's name
- * @param string $name The author's name
+ * @param string $label The label
+ * @param string $name The name
*/
public function __construct($label, $name)
{
diff --git a/libraries/incubator/Extension/FileExtensionFactory.php b/libraries/incubator/Extension/FileExtensionFactory.php
index 7560b0320d..1feb464beb 100644
--- a/libraries/incubator/Extension/FileExtensionFactory.php
+++ b/libraries/incubator/Extension/FileExtensionFactory.php
@@ -141,7 +141,12 @@ private function createQueryHandlers(Extension $extension, array $handlersConfig
{
foreach ($handlersConfig as $handler)
{
- $extension->addQueryHandler($handler['query'], new $handler['class']($this->container->get('CommandBus'), $this->container->get('EventDispatcher')));
+ $handlerInstance = new $handler['class']($this->container->get('CommandBus'), $this->container->get('EventDispatcher'));
+ if (method_exists($handlerInstance, 'setSession') && $this->container->has('Session'))
+ {
+ $handlerInstance->setSession($this->container->get('Session'));
+ }
+ $extension->addQueryHandler($handler['query'], $handlerInstance);
}
}
}
diff --git a/libraries/incubator/Session/SessionAwareTrait.php b/libraries/incubator/Session/SessionAwareTrait.php
new file mode 100644
index 0000000000..c36ddd29cb
--- /dev/null
+++ b/libraries/incubator/Session/SessionAwareTrait.php
@@ -0,0 +1,53 @@
+session;
+ }
+
+ /**
+ * Set the session to use.
+ *
+ * @param SessionInterface $session The session to use.
+ *
+ * @return $this
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function setSession(SessionInterface $session)
+ {
+ $this->session = $session;
+
+ return $this;
+ }
+}