update, delete entity relations
This commit is contained in:
@ -203,4 +203,22 @@ class EntityRelation
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function deleteEntityRelationBySlug(string $slug, string $entity, Model $model): void
|
||||
{
|
||||
$moduleClass = $this->getAdditionalPropertyClassBySlug($slug);
|
||||
if ($moduleClass and method_exists($moduleClass, "deleteItems")) {
|
||||
$moduleClass->deleteItems($entity, $model);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteEntityRelation(string $entity, Model $model): void
|
||||
{
|
||||
$relations = $this->getEntityRelationsBySlug($entity);
|
||||
if ($relations){
|
||||
foreach ($relations as $relation){
|
||||
$this->deleteEntityRelationBySlug($relation, $entity, $model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -93,6 +93,10 @@ class PostController extends AdminController
|
||||
$postForm->load($_REQUEST);
|
||||
if ($postForm->validate()) {
|
||||
$post = $this->postService->update($postForm, $post);
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->saveEntityRelation(entity: "post", model: $post, request: new Request());
|
||||
|
||||
if ($post) {
|
||||
$this->redirect("/admin/post/view/" . $post->id);
|
||||
}
|
||||
@ -109,6 +113,10 @@ class PostController extends AdminController
|
||||
if (!$post){
|
||||
throw new Exception(message: "The post not found");
|
||||
}
|
||||
|
||||
$entityRelation = new EntityRelation();
|
||||
$entityRelation->deleteEntityRelation(entity: "post", model: $post);
|
||||
|
||||
$post->delete();
|
||||
$this->redirect("/admin/post/");
|
||||
}
|
||||
|
Reference in New Issue
Block a user