/**
* @Route("/edit/{id}", name="dashboard_book_edit", methods="GET|POST")
*/
public function edit(Request $request, Book $book): Response
{
$book->setCover(
new File($this->getParameter('app_storage').'/'.$book->getCover())
);
$form = $this->createForm(BookEditType::class, $book);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('book_edit', ['id' => $book->getId()]);
}
return $this->render('dashboard/book/edit.html.twig', [
'book' => $book,
'editForm' => $form->createView(),
]);
}
class BookEditType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('cover', FileType::class)
->add('slug', TextType::class)
->add('name', TextType::class)
->add('description', TextareaType::class)
->add('plot', TextareaType::class)
->add('published_at', DateType::class, [
'years' => range(date('Y') - 25, date('Y')),
])
->add('save', SubmitType::class);
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Book::class,
]);
}
}
->add('cover', FileType::class, [ 'data_class' => null])
When creating a form to edit an already persisted item, the file form type still expects a File instance. As the persisted entity now contains only the relative file path, you first have to concatenate the configured upload path with the stored filename and create a new File class:use Symfony\Component\HttpFoundation\File\File; // ... $product->setBrochure( new File($this->getParameter('brochures_directory').'/'.$product->getBrochure()) );
var nodes = div.querySelectorAll('p');
var first = nodes[0];
var last = nodes[nodes.length- 1];
last.remove();