delete composition ajax link is working !
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user