diff --git a/src/Entity/Book.php b/src/Entity/Book.php index e0b679e8..0b1047a8 100644 --- a/src/Entity/Book.php +++ b/src/Entity/Book.php @@ -335,6 +335,32 @@ public function removeAuthor(string $author): static return $this; } + public function addTag(string $tag): static + { + if ($this->tags === null) { + $this->tags = []; + } + if (!in_array($tag, $this->tags, true)) { + $this->tags[] = $tag; + } + + return $this; + } + + public function removeTag(string $tag): static + { + if ($this->tags === null) { + $this->tags = []; + } + foreach ($this->tags as $key => $value) { + if ($value === $tag) { + unset($this->tags[$key]); + } + } + + return $this; + } + public function getExtension(): string { return $this->extension; diff --git a/src/Twig/InlineEditBook.php b/src/Twig/InlineEditBook.php index ee3e590f..9ce8e4aa 100644 --- a/src/Twig/InlineEditBook.php +++ b/src/Twig/InlineEditBook.php @@ -55,7 +55,13 @@ public function usesuggestion(#[LiveArg] string $field, #[LiveArg] string $sugge $value = $this->suggestions[$field][$suggestion]; if (is_callable([$this->book, $to_call])) { /* @phpstan-ignore-next-line */ - $this->book->$to_call($value); + if($field==='tags'){ + $this->book->addTag($value); + }elseif($field==='authors'){ + $this->book->addAuthor($value); + }else { + $this->book->$to_call($value); + } } }