mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 15:03:44 +08:00
Extensibility: data when starting a new discussion
This commit is contained in:
parent
50e4dbf3b4
commit
ce0c8903a5
|
@ -50,14 +50,18 @@ export default class ComposerDiscussion extends ComposerBody {
|
||||||
return (this.title() || this.content()) && !confirm(this.props.confirmExit);
|
return (this.title() || this.content()) && !confirm(this.props.confirmExit);
|
||||||
}
|
}
|
||||||
|
|
||||||
onsubmit(content) {
|
data() {
|
||||||
|
return {
|
||||||
|
title: this.title(),
|
||||||
|
content: this.content()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
onsubmit() {
|
||||||
this.loading(true);
|
this.loading(true);
|
||||||
m.redraw();
|
m.redraw();
|
||||||
|
|
||||||
var data = {
|
var data = this.data();
|
||||||
title: this.title(),
|
|
||||||
content: content
|
|
||||||
};
|
|
||||||
|
|
||||||
app.store.createRecord('discussions').save(data).then(discussion => {
|
app.store.createRecord('discussions').save(data).then(discussion => {
|
||||||
app.composer.hide();
|
app.composer.hide();
|
||||||
|
|
|
@ -2,19 +2,16 @@
|
||||||
|
|
||||||
class StartDiscussionCommand
|
class StartDiscussionCommand
|
||||||
{
|
{
|
||||||
public $title;
|
|
||||||
|
|
||||||
public $content;
|
|
||||||
|
|
||||||
public $user;
|
public $user;
|
||||||
|
|
||||||
public $forum;
|
public $forum;
|
||||||
|
|
||||||
public function __construct($title, $content, $user, $forum)
|
public $data;
|
||||||
|
|
||||||
|
public function __construct($user, $forum, $data)
|
||||||
{
|
{
|
||||||
$this->title = $title;
|
|
||||||
$this->content = $content;
|
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->forum = $forum;
|
$this->forum = $forum;
|
||||||
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ class StartDiscussionCommandHandler
|
||||||
// an opportunity to alter the discussion entity based on data in the
|
// an opportunity to alter the discussion entity based on data in the
|
||||||
// command they may have passed through in the controller.
|
// command they may have passed through in the controller.
|
||||||
$discussion = Discussion::start(
|
$discussion = Discussion::start(
|
||||||
$command->title,
|
array_get($command->data, 'title'),
|
||||||
$command->user
|
$command->user
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -41,13 +41,9 @@ class StartDiscussionCommandHandler
|
||||||
// will trigger a domain event that is slightly semantically incorrect
|
// will trigger a domain event that is slightly semantically incorrect
|
||||||
// in this situation (PostWasPosted), we may need to reconsider someday.
|
// in this situation (PostWasPosted), we may need to reconsider someday.
|
||||||
$post = $this->bus->dispatch(
|
$post = $this->bus->dispatch(
|
||||||
new PostReplyCommand($discussion->id, $command->content, $command->user)
|
new PostReplyCommand($discussion->id, array_get($command->data, 'content'), $command->user)
|
||||||
);
|
);
|
||||||
|
|
||||||
// The discussion may have been updated by the PostReplyCommand; we need
|
return $post->discussion;
|
||||||
// to refresh its data.
|
|
||||||
$discussion = $post->discussion;
|
|
||||||
|
|
||||||
return $discussion;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user