delete composition ajax link is working !

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-24 11:40:51 +01:00
parent 6cc38d3300
commit eed0b50970
7 changed files with 268 additions and 37 deletions
@@ -61,9 +61,13 @@ class CompositionController extends ControllerBase {
$this->error_message = t("Composition creation needs a name as query paramater!");
}
break;
// case 'delete':
//
// break;
case 'delete':
if($cid){
$this->deleteComposition($cid);
}else{
$this->error_message = t("Composition deletion needs a cid as url paramater!");
}
break;
// case 'rename':
//
// break;
@@ -71,39 +75,46 @@ class CompositionController extends ControllerBase {
if($this->error_message){
$status = 'error';
}
if($status == 'error'){
$message = $this->error_message;
}else{
$url = Url::fromRoute('entity.composition.canonical', ['composition' => $this->compo->id()], ['absolute' => TRUE]);
$title = $this->compo->getName();
$new_link_build = array(
'#title' => $title,
'#type' => 'link',
'#url' => $url,
'#options'=>array(
'attributes' => array(
'data-drupal-link-system-path' => $url->getInternalPath(),
'nid' => $this->compo->id(),
'class' => ['composition-link'],
'title'=>$title,
),
),
);
$new_link = render($new_link_build);
}
// JSON
$response = new JsonResponse();
$data = array(
'action' => $action,
'status' => $status,
'message' => $this->error_message,
'new_name' => $request->query->get('new_name'),
'new_link' => $new_link,
'message' => $this->error_message
);
if($status == 'ok'){
switch ($action) {
case 'create':
$url = Url::fromRoute('entity.composition.canonical', ['composition' => $this->compo->id()], ['absolute' => TRUE]);
$title = $this->compo->getName();
$new_link_build = array(
'#title' => $title,
'#type' => 'link',
'#url' => $url,
'#options'=>array(
'attributes' => array(
'data-drupal-link-system-path' => $url->getInternalPath(),
'nid' => $this->compo->id(),
'class' => ['composition-link'],
'title'=>$title,
),
),
);
$data += array(
'new_name' => $title,
'new_link' => render($new_link_build),
);
break;
// case 'delete':
// # code...
// break;
}
}
$response->setData($data);
return $response;
@@ -124,4 +135,8 @@ class CompositionController extends ControllerBase {
$this->compo->save();
}
private function deleteComposition($cid){
$this->compo = entity_load('composition', $cid);
$this->compo->delete();
}
}