[Repeat][Favourite] Only display action buttons if logged in (instead of forcing login)
This commit is contained in:
parent
7af424b64a
commit
6b1689e1df
|
@ -34,7 +34,13 @@ class Favourite extends Module
|
||||||
{
|
{
|
||||||
public function onAddNoteActions(Request $request, Note $note, array &$actions)
|
public function onAddNoteActions(Request $request, Note $note, array &$actions)
|
||||||
{
|
{
|
||||||
$opts = ['note_id' => $note->getId(), 'gsactor_id' => Common::ensureLoggedIn()->getActor()->getId()];
|
$user = Common::user();
|
||||||
|
// Only show buttons if a user is logged in
|
||||||
|
if ($user == null) {
|
||||||
|
return Event::next;
|
||||||
|
}
|
||||||
|
|
||||||
|
$opts = ['note_id' => $note->getId(), 'gsactor_id' => $user->getId()];
|
||||||
$is_set = DB::find('favourite', $opts) != null;
|
$is_set = DB::find('favourite', $opts) != null;
|
||||||
$form = Form::create([
|
$form = Form::create([
|
||||||
['is_set', HiddenType::class, ['data' => $is_set ? '1' : '0']],
|
['is_set', HiddenType::class, ['data' => $is_set ? '1' : '0']],
|
||||||
|
@ -62,7 +68,7 @@ class Favourite extends Module
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$actions['post_fav'] = $form->createView();
|
$actions[] = $form->createView();
|
||||||
return Event::next;
|
return Event::next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ use App\Core\Event;
|
||||||
use App\Core\Form;
|
use App\Core\Form;
|
||||||
use App\Core\Module;
|
use App\Core\Module;
|
||||||
use App\Entity\Note;
|
use App\Entity\Note;
|
||||||
|
use App\Util\Common;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
@ -32,6 +33,12 @@ class Repeat extends Module
|
||||||
{
|
{
|
||||||
public function onAddNoteActions(Request $request, Note $note, array &$actions)
|
public function onAddNoteActions(Request $request, Note $note, array &$actions)
|
||||||
{
|
{
|
||||||
|
$user = Common::user();
|
||||||
|
// Only show buttons if a user is logged in
|
||||||
|
if ($user == null) {
|
||||||
|
return Event::next;
|
||||||
|
}
|
||||||
|
|
||||||
$to_repeat = DB::find('note', ['id' => $note->getId()]);
|
$to_repeat = DB::find('note', ['id' => $note->getId()]);
|
||||||
$is_set = false;
|
$is_set = false;
|
||||||
$form = Form::create([
|
$form = Form::create([
|
||||||
|
@ -47,9 +54,7 @@ class Repeat extends Module
|
||||||
if ($data['note_id'] == $to_repeat && $form->isValid()) {
|
if ($data['note_id'] == $to_repeat && $form->isValid()) {
|
||||||
// Loose comparison
|
// Loose comparison
|
||||||
if (!$data['is_set']) {
|
if (!$data['is_set']) {
|
||||||
var_dump($note);
|
DB::persist(Note::create(['gsactor_id' => $user->getId(), 'repeat_of' => $note->getId(), 'content' => $note->getContent(), 'is_local' => true]));
|
||||||
die();
|
|
||||||
DB::persist(Note::create(['repeat_of' => $note->getId(), 'content' => $note->getContent(), 'is_local' => true]));
|
|
||||||
DB::flush();
|
DB::flush();
|
||||||
} else {
|
} else {
|
||||||
DB::remove($to_repeat);
|
DB::remove($to_repeat);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user