Allow to add a comment when editing/creating/deleting an element.

This commit is contained in:
Jan Böhmer 2020-02-23 00:44:52 +01:00
parent c14d6d91ff
commit b6f95ebe48
19 changed files with 421 additions and 47 deletions

View file

@ -52,6 +52,7 @@ use App\Services\Attachments\AttachmentManager;
use App\Services\Attachments\AttachmentSubmitHandler;
use App\Services\EntityExporter;
use App\Services\EntityImporter;
use App\Services\LogSystem\EventCommentHelper;
use App\Services\StructuralElementRecursionHelper;
use Doctrine\ORM\EntityManagerInterface;
use InvalidArgumentException;
@ -77,9 +78,11 @@ abstract class BaseAdminController extends AbstractController
protected $translator;
protected $attachmentHelper;
protected $attachmentSubmitHandler;
protected $commentHelper;
public function __construct(TranslatorInterface $translator, UserPasswordEncoderInterface $passwordEncoder,
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler)
AttachmentManager $attachmentHelper, AttachmentSubmitHandler $attachmentSubmitHandler,
EventCommentHelper $commentHelper)
{
if ('' === $this->entity_class || '' === $this->form_class || '' === $this->twig_template || '' === $this->route_base) {
throw new InvalidArgumentException('You have to override the $entity_class, $form_class, $route_base and $twig_template value in your subclasss!');
@ -93,6 +96,7 @@ abstract class BaseAdminController extends AbstractController
$this->passwordEncoder = $passwordEncoder;
$this->attachmentHelper = $attachmentHelper;
$this->attachmentSubmitHandler = $attachmentSubmitHandler;
$this->commentHelper = $commentHelper;
}
@ -131,6 +135,8 @@ abstract class BaseAdminController extends AbstractController
}
}
$this->commentHelper->setMessage($form['log_comment']->getData());
$em->persist($entity);
$em->flush();
$this->addFlash('success', 'entity.edit_flash');
@ -188,6 +194,8 @@ abstract class BaseAdminController extends AbstractController
}
}
$this->commentHelper->setMessage($form['log_comment']->getData());
$em->persist($new_entity);
$em->flush();
$this->addFlash('success', 'entity.created_flash');
@ -215,6 +223,10 @@ abstract class BaseAdminController extends AbstractController
'csv_separator' => $data['csv_separator'],
];
$this->commentHelper->setMessage('Import ' . $file->getClientOriginalName());
$errors = $importer->fileToDBEntities($file, $this->entity_class, $options);
foreach ($errors as $name => $error) {
@ -280,6 +292,8 @@ abstract class BaseAdminController extends AbstractController
$entityManager->remove($entity);
}
$this->commentHelper->setMessage($request->request->get('log_comment', null));
//Flush changes
$entityManager->flush();