Implement snip content names
This commit is contained in:
@ -104,7 +104,11 @@ class SnipController extends AbstractController
|
||||
]);
|
||||
}
|
||||
$this->repository->save($snip);
|
||||
$contentService->update($snip, $form->get('content')->getData());
|
||||
$contentService->update(
|
||||
$snip,
|
||||
$form->get('content')->getData(),
|
||||
$form->get('contentName')->getData()
|
||||
);
|
||||
|
||||
$this->addFlash('success', sprintf('Snip "%s" saved', $snip));
|
||||
|
||||
|
@ -35,6 +35,9 @@ class SnipContent
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?array $diff = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->children = new ArrayCollection();
|
||||
@ -122,4 +125,16 @@ class SnipContent
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(?string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,9 @@ use App\Entity\Snip;
|
||||
use App\Service\SnipParser\ParserFactory;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -31,6 +33,10 @@ class SnipType extends AbstractType
|
||||
->add('tags', TagsType::class)
|
||||
->add('public', SwitchType::class)
|
||||
->add('visible', SwitchType::class)
|
||||
->add('contentName', TextType::class, [
|
||||
'label' => 'Change description (optional)',
|
||||
'mapped' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -13,18 +13,19 @@ readonly class SnipContentService
|
||||
private EntityManagerInterface $em,
|
||||
) {}
|
||||
|
||||
public function update(Snip $snip, string $snipContents): void
|
||||
public function update(Snip $snip, string $contents, ?string $contentName): void
|
||||
{
|
||||
$parentContent = $snip->getActiveVersion();
|
||||
if (self::rebuildText($parentContent) === $snipContents) {
|
||||
if (self::rebuildText($parentContent) === $contents) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create new snipContent entity with previous one as parent
|
||||
$content = new SnipContent();
|
||||
$content
|
||||
->setText($snipContents)
|
||||
->setText($contents)
|
||||
->setSnip($snip)
|
||||
->setName($contentName)
|
||||
;
|
||||
if ($parentContent !== null) {
|
||||
$content->setParent($parentContent);
|
||||
|
Reference in New Issue
Block a user