Skip to content

Commit

Permalink
Fix tag add
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMendolia committed Sep 6, 2023
1 parent 6e49e60 commit e71715c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/Entity/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/Twig/InlineEditBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit e71715c

Please sign in to comment.