backports murph-skeleton
This commit is contained in:
parent
77c234987d
commit
aca3b7d676
|
@ -43,7 +43,7 @@ abstract class CrudController extends AdminController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function doNew(EntityInterface $entity, EntityManager $entityManager, Request $request): Response
|
protected function doNew(EntityInterface $entity, EntityManager $entityManager, Request $request, callable $beforeCreate = null): Response
|
||||||
{
|
{
|
||||||
$configuration = $this->getConfiguration();
|
$configuration = $this->getConfiguration();
|
||||||
$form = $this->createForm($configuration->getForm('new'), $entity);
|
$form = $this->createForm($configuration->getForm('new'), $entity);
|
||||||
|
@ -52,6 +52,10 @@ abstract class CrudController extends AdminController
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isValid()) {
|
if ($form->isValid()) {
|
||||||
|
if ($beforeCreate !== null) {
|
||||||
|
call_user_func_array($beforeCreate, [$entity, $form, $request]);
|
||||||
|
}
|
||||||
|
|
||||||
$entityManager->create($entity);
|
$entityManager->create($entity);
|
||||||
$this->addFlash('success', 'The data has been saved.');
|
$this->addFlash('success', 'The data has been saved.');
|
||||||
|
|
||||||
|
@ -79,7 +83,7 @@ abstract class CrudController extends AdminController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function doEdit(EntityInterface $entity, EntityManager $entityManager, Request $request): Response
|
protected function doEdit(EntityInterface $entity, EntityManager $entityManager, Request $request, callable $beforeUpdate = null): Response
|
||||||
{
|
{
|
||||||
$configuration = $this->getConfiguration();
|
$configuration = $this->getConfiguration();
|
||||||
$form = $this->createForm($configuration->getForm('edit'), $entity);
|
$form = $this->createForm($configuration->getForm('edit'), $entity);
|
||||||
|
@ -88,6 +92,10 @@ abstract class CrudController extends AdminController
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
if ($form->isValid()) {
|
if ($form->isValid()) {
|
||||||
|
if ($beforeUpdate !== null) {
|
||||||
|
call_user_func_array($beforeUpdate, [$entity, $form, $request]);
|
||||||
|
}
|
||||||
|
|
||||||
$entityManager->update($entity);
|
$entityManager->update($entity);
|
||||||
$this->addFlash('success', 'The data has been saved.');
|
$this->addFlash('success', 'The data has been saved.');
|
||||||
|
|
||||||
|
@ -105,11 +113,15 @@ abstract class CrudController extends AdminController
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function doDelete(EntityInterface $entity, EntityManager $entityManager, Request $request): Response
|
protected function doDelete(EntityInterface $entity, EntityManager $entityManager, Request $request, callable $beforeDelete = null): Response
|
||||||
{
|
{
|
||||||
$configuration = $this->getConfiguration();
|
$configuration = $this->getConfiguration();
|
||||||
|
|
||||||
if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) {
|
if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) {
|
||||||
|
if ($beforeDelete !== null) {
|
||||||
|
call_user_func($beforeDelete, $entity);
|
||||||
|
}
|
||||||
|
|
||||||
$entityManager->delete($entity);
|
$entityManager->delete($entity);
|
||||||
|
|
||||||
$this->addFlash('success', 'The data has been removed.');
|
$this->addFlash('success', 'The data has been removed.');
|
||||||
|
|
|
@ -17,6 +17,7 @@ abstract class Field
|
||||||
public function buildView(Environment $twig, $entity, array $options)
|
public function buildView(Environment $twig, $entity, array $options)
|
||||||
{
|
{
|
||||||
return $twig->render($this->getView($options), [
|
return $twig->render($this->getView($options), [
|
||||||
|
'entity' => $entity,
|
||||||
'value' => $this->getValue($entity, $options),
|
'value' => $this->getValue($entity, $options),
|
||||||
'options' => $options,
|
'options' => $options,
|
||||||
]);
|
]);
|
||||||
|
@ -53,7 +54,7 @@ abstract class Field
|
||||||
} elseif (null !== $options['property_builder']) {
|
} elseif (null !== $options['property_builder']) {
|
||||||
$value = call_user_func($options['property_builder'], $entity, $options);
|
$value = call_user_func($options['property_builder'], $entity, $options);
|
||||||
} else {
|
} else {
|
||||||
throw new CrudConfigurationException('Unable to get the value. One of "property" and "property_builder" is required.');
|
$value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
|
|
@ -1 +1,4 @@
|
||||||
{{ value|date(options.format) }}
|
<span class="btn btn-sm btn-light">
|
||||||
|
<span class="fa fa-calendar-alt text-black-50 mr-1"></span>
|
||||||
|
{{ value|date(options.format) }}
|
||||||
|
</span>
|
||||||
|
|
Loading…
Reference in a new issue